hextoy 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +11 -4
- package/src/index.js +14 -0
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# hextoy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
simple ahh hex dump thing
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hextoy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"exports": "./src/index.js",
|
|
12
|
+
"main": "./src/index.js"
|
|
13
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function toHex(input, width = 16) {
|
|
2
|
+
const buf = Buffer.isBuffer(input) ? input : Buffer.from(String(input), "utf8");
|
|
3
|
+
const lines = [];
|
|
4
|
+
|
|
5
|
+
for (let offset = 0; offset < buf.length; offset += width) {
|
|
6
|
+
const slice = buf.subarray(offset, offset + width);
|
|
7
|
+
const hex = Array.from(slice, (b) => b.toString(16).padStart(2,"0")).join(" ");
|
|
8
|
+
const ascii = Array.from(slice, (b) => (b >= 32 && b <= 126 ? String.fromCharCode(b) : ".")).join("");
|
|
9
|
+
const addr = offset.toString(16).padStart(8, "0");
|
|
10
|
+
lines.push(`${addr} ${hex.padEnd(width * 3 - 1, " ")} |${ascii}|`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return lines.join("\n");
|
|
14
|
+
}
|