Compare commits

..

1 Commits
master ... old

Author SHA1 Message Date
71aa9815e8 v1.1.0: update urls 2019-10-19 23:06:51 -06:00
8 changed files with 25 additions and 129 deletions

View File

@ -1,4 +1,4 @@
# [@root/hexdump](https://git.rootprojects.org/root/hexdump.js)
# [hexdump.js](https://git.rootprojects.org/root/hexdump.js)
| Built by [Root](https://rootprojects.org)
@ -40,25 +40,23 @@ console.log(str);
console.log(window.hexdump(new Uint8Array([0, 1, 2, 127, 254, 255])));
```
### CLI
## CLI
```bash
hexdump.js <filepath>
```
## Install
Centralized:
# Install
```bash
# As a library
npm install --save @root/hexdump
npm install --save @hexdump.js
# As a global CLI (useful on windows)
npm install --global @root/hexdump
npm install --global @hexdump.js
```
## API
# API
```js
hexdump(arrayBuffer, byteOffset, byteLength);

View File

@ -1,30 +1,4 @@
#!/usr/bin/env node
'use strict';
var hexdump = require('../');
var fsname = process.argv[2];
var fs = require('fs');
var opts = {};
if (!fsname || '--help' === fsname || '-h' === fsname) {
console.error('Usage: hexdump.js -C <filepath>');
process.exit(2);
return;
}
if ('-C' === fsname) {
opts.C = true;
fsname = process.argv[3];
}
try {
fs.statSync(fsname);
} catch (e) {
console.error(e.message);
process.exit(3);
return;
}
var nb = fs.readFileSync(fsname);
var str = hexdump(nb.buffer, nb.byteOffset, nb.byteLength, opts);
console.info(str);
require('@root/hexdump/bin/cli.js');

View File

@ -1,16 +0,0 @@
#!/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
View File

@ -1,70 +0,0 @@
;(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
View File

@ -1 +0,0 @@
(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})();

14
package-lock.json generated
View File

@ -1,5 +1,13 @@
{
"name": "@root/hexdump",
"version": "1.1.1",
"lockfileVersion": 1
"name": "hexdump.js",
"version": "1.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@root/hexdump": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@root/hexdump/-/hexdump-1.1.0.tgz",
"integrity": "sha512-D0KpG8OkJUEP2GixkIjjLoB9P6t2KruAirnmKL5utT1Ma16S26vwG4ibLVBqG6rySaUDaCx7YMRH+5zzZS5jQw=="
}
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@root/hexdump",
"version": "1.1.1",
"name": "hexdump.js",
"version": "1.1.0",
"description": "Like hexdump on *nix, but in JavaScript.",
"main": "hexdump.js",
"homepage": "https://git.rootprojects.org/root/hexdump.js",
@ -21,5 +21,8 @@
"js"
],
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)",
"license": "MPL-2.0"
"license": "MPL-2.0",
"dependencies": {
"@root/hexdump": "^1.1.0"
}
}

View File

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