v1.1.1: add browser dist file

This commit is contained in:
AJ ONeal 2019-10-19 23:13:19 -06:00
parent a8af9bb209
commit cce1b04a1e
7 changed files with 107 additions and 7 deletions

View File

@ -1,4 +1,4 @@
# @root/hexdump # [@root/hexdump](https://git.rootprojects.org/root/hexdump.js)
| Built by [Root](https://rootprojects.org) | Built by [Root](https://rootprojects.org)
@ -12,21 +12,29 @@ For example, the text of "Hello, World!\n" looks something like this:
000000e 000000e
``` ```
## Usage # Usage
So far it just does one thing: print an ArrayBuffer in hex, with a header: So far it just does one thing: print an ArrayBuffer in hex, with a header:
### JavaScript ## Node.js (and WebPack)
```bash ```bash
var hexdump = require('@root/hexdump').hexdump; var hexdump = require('hexdump.js').hexdump;
var str = hexdump(new Uint8Array([ 0, 1, 2, 127, 254, 255 ])); var str = hexdump(new Uint8Array([ 0, 1, 2, 127, 254, 255 ]));
console.log(str); console.log(str);
``` ```
### Browser ## Vanilla JS (Browser)
```html
<script src="https://unpkg.com/@root/hexdump/dist/hexdump.js"></script>
```
```html
<script src="https://unpkg.com/@root/hexdump/dist/hexdump.min.js"></script>
```
```javascript ```javascript
console.log(window.hexdump(new Uint8Array([0, 1, 2, 127, 254, 255]))); console.log(window.hexdump(new Uint8Array([0, 1, 2, 127, 254, 255])));

16
build.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
# TODO convert to JS
cat hexdump.js > all.tmp.js
sed -i '' '/use strict/d' all.tmp.js
sed -i '' '/require/d' all.tmp.js
sed -i '' '/exports/d' all.tmp.js
echo ';(function () {' > all.js
echo "'use strict';" >> all.js
cat all.tmp.js >> all.js
rm all.tmp.js
echo "window.hexdump = hexdump;" >> all.js
echo '}());' >> all.js
mv all.js dist/hexdump.js
uglifyjs dist/hexdump.js > dist/hexdump.min.js

70
dist/hexdump.js vendored Normal file
View File

@ -0,0 +1,70 @@
;(function () {
'use strict';
function hexdump(ab, offset, len, opts) {
if (!opts) {
opts = {};
}
var ui8 = new Uint8Array(ab.buffer || ab, offset || ab.byteOffset, len || ab.byteLength);
var bytecount = 0;
var head = ' 0 1 2 3 4 5 6 7 8 9 A B C D E F';
var trail;
var str = [].slice
.call(ui8)
.map(function(i) {
var h = i.toString(16);
if (h.length < 2) {
h = '0' + h;
}
return h;
})
.join('')
.match(/.{1,2}/g)
.join(' ')
.match(/.{1,48}/g)
.map(function(str) {
var lead = bytecount.toString(16);
bytecount += 16;
while (lead.length < 7) {
lead = '0' + lead;
}
while (str.length < 48) {
str += ' ';
}
if (opts.C) {
return (
lead +
' ' +
str +
' |' +
str
.replace(/ /g, '')
.match(/.{1,2}/g)
.map(function(ch) {
var c = String.fromCharCode(parseInt(ch, 16));
if (!/[ -~]/.test(c)) {
c = '.';
}
return c;
})
.join('') +
'|'
);
} else {
return lead + ' ' + str;
}
})
.join('\n');
trail = (len || ab.byteLength).toString(16);
while (trail.length < 7) {
trail = '0' + trail;
}
return head + '\n' + str + '\n' + trail;
}
window.hexdump = hexdump;
}());

1
dist/hexdump.min.js vendored Normal file
View File

@ -0,0 +1 @@
(function(){"use strict";function hexdump(ab,offset,len,opts){if(!opts){opts={}}var ui8=new Uint8Array(ab.buffer||ab,offset||ab.byteOffset,len||ab.byteLength);var bytecount=0;var head=" 0 1 2 3 4 5 6 7 8 9 A B C D E F";var trail;var str=[].slice.call(ui8).map(function(i){var h=i.toString(16);if(h.length<2){h="0"+h}return h}).join("").match(/.{1,2}/g).join(" ").match(/.{1,48}/g).map(function(str){var lead=bytecount.toString(16);bytecount+=16;while(lead.length<7){lead="0"+lead}while(str.length<48){str+=" "}if(opts.C){return lead+" "+str+" |"+str.replace(/ /g,"").match(/.{1,2}/g).map(function(ch){var c=String.fromCharCode(parseInt(ch,16));if(!/[ -~]/.test(c)){c="."}return c}).join("")+"|"}else{return lead+" "+str}}).join("\n");trail=(len||ab.byteLength).toString(16);while(trail.length<7){trail="0"+trail}return head+"\n"+str+"\n"+trail}window.hexdump=hexdump})();

5
package-lock.json generated Normal file
View File

@ -0,0 +1,5 @@
{
"name": "@root/hexdump",
"version": "1.1.1",
"lockfileVersion": 1
}

View File

@ -1,6 +1,6 @@
{ {
"name": "@root/hexdump", "name": "@root/hexdump",
"version": "1.1.0", "version": "1.1.1",
"description": "Like hexdump on *nix, but in JavaScript.", "description": "Like hexdump on *nix, but in JavaScript.",
"main": "hexdump.js", "main": "hexdump.js",
"homepage": "https://git.rootprojects.org/root/hexdump.js", "homepage": "https://git.rootprojects.org/root/hexdump.js",

View File

@ -1 +1 @@
Hello, World! Hello, 世界!