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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/package.json +11 -4
  3. package/src/index.js +14 -0
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Temporary Holding Version
1
+ # hextoy
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ simple ahh hex dump thing
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "hextoy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
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
+ }