Compare commits
	
		
			1 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 71aa9815e8 | 
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							| @ -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) | | 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]))); | console.log(window.hexdump(new Uint8Array([0, 1, 2, 127, 254, 255]))); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ### CLI | ## CLI | ||||||
| 
 | 
 | ||||||
| ```bash | ```bash | ||||||
| hexdump.js <filepath> | hexdump.js <filepath> | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ## Install | # Install | ||||||
| 
 |  | ||||||
| Centralized: |  | ||||||
| 
 | 
 | ||||||
| ```bash | ```bash | ||||||
| # As a library | # As a library | ||||||
| npm install --save @root/hexdump | npm install --save @hexdump.js | ||||||
| 
 | 
 | ||||||
| # As a global CLI (useful on windows) | # As a global CLI (useful on windows) | ||||||
| npm install --global @root/hexdump | npm install --global @hexdump.js | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ## API | # API | ||||||
| 
 | 
 | ||||||
| ```js | ```js | ||||||
| hexdump(arrayBuffer, byteOffset, byteLength); | hexdump(arrayBuffer, byteOffset, byteLength); | ||||||
|  | |||||||
							
								
								
									
										28
									
								
								bin/cli.js
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								bin/cli.js
									
									
									
									
									
								
							| @ -1,30 +1,4 @@ | |||||||
| #!/usr/bin/env node
 | #!/usr/bin/env node
 | ||||||
| 'use strict'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
| var hexdump = require('../'); | require('@root/hexdump/bin/cli.js'); | ||||||
| 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); |  | ||||||
|  | |||||||
							
								
								
									
										16
									
								
								build.sh
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								build.sh
									
									
									
									
									
								
							| @ -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
									
									
								
							
							
						
						
									
										70
									
								
								dist/hexdump.js
									
									
									
									
										vendored
									
									
								
							| @ -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
									
									
								
							
							
						
						
									
										1
									
								
								dist/hexdump.min.js
									
									
									
									
										vendored
									
									
								
							| @ -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
									
									
									
								
							
							
						
						
									
										14
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -1,5 +1,13 @@ | |||||||
| { | { | ||||||
| 	"name": "@root/hexdump", | 	"name": "hexdump.js", | ||||||
| 	"version": "1.1.1", | 	"version": "1.1.0", | ||||||
| 	"lockfileVersion": 1 | 	"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==" | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
| 	"name": "@root/hexdump", | 	"name": "hexdump.js", | ||||||
| 	"version": "1.1.1", | 	"version": "1.1.0", | ||||||
| 	"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", | ||||||
| @ -21,5 +21,8 @@ | |||||||
| 		"js" | 		"js" | ||||||
| 	], | 	], | ||||||
| 	"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)", | 	"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)", | ||||||
| 	"license": "MPL-2.0" | 	"license": "MPL-2.0", | ||||||
|  | 	"dependencies": { | ||||||
|  | 		"@root/hexdump": "^1.1.0" | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user