@thi.ng/hex 2.3.85 → 2.4.1

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 CHANGED
@@ -20,6 +20,7 @@
20
20
  - [Installation](#installation)
21
21
  - [Dependencies](#dependencies)
22
22
  - [API](#api)
23
+ - [Creating hexdumps](#creating-hexdumps)
23
24
  - [Authors](#authors)
24
25
  - [License](#license)
25
26
 
@@ -63,7 +64,7 @@ For Node.js REPL:
63
64
  const hex = await import("@thi.ng/hex");
64
65
  ```
65
66
 
66
- Package sizes (brotli'd, pre-treeshake): ESM: 631 bytes
67
+ Package sizes (brotli'd, pre-treeshake): ESM: 616 bytes
67
68
 
68
69
  ## Dependencies
69
70
 
@@ -73,7 +74,7 @@ None
73
74
 
74
75
  [Generated API docs](https://docs.thi.ng/umbrella/hex/)
75
76
 
76
- ```ts
77
+ ```ts tangle:export/readme.ts
77
78
  import * as h from "@thi.ng/hex";
78
79
 
79
80
  const cssColor = (x: number) => "#" + h.U24(x);
@@ -113,6 +114,32 @@ h.U32LE(BUF, 4)
113
114
  // "40302010"
114
115
  ```
115
116
 
117
+ ### Creating hexdumps
118
+
119
+ The following functions are provided to create customizable hexdumps:
120
+
121
+ - [hexdump()](https://docs.thi.ng/umbrella/hex/functions/hexdump.html)
122
+ - [hexdumpLines()](https://docs.thi.ng/umbrella/hex/functions/hexdumpLines.html)
123
+ - [printHexdump()](https://docs.thi.ng/umbrella/hex/functions/printHexdump.html)
124
+
125
+ ```ts tangle:export/readme-hexdump.ts
126
+ import { printHexdump } from "@thi.ng/hex";
127
+ import { readFileSync } from "node:fs";
128
+
129
+ const bytes = readFileSync("README.md");
130
+
131
+ // hexdump of the first 100 bytes
132
+ printHexdump(bytes, 0, 100);
133
+
134
+ // 00000000 21 5b 74 68 69 2e 6e 67 2f 75 6d 62 72 65 6c 6c ![thi.ng/umbrell
135
+ // 00000010 61 5d 28 68 74 74 70 73 3a 2f 2f 72 61 77 2e 67 a](https://raw.g
136
+ // 00000020 69 74 68 75 62 75 73 65 72 63 6f 6e 74 65 6e 74 ithubusercontent
137
+ // 00000030 2e 63 6f 6d 2f 74 68 69 2d 6e 67 2f 75 6d 62 72 .com/thi-ng/umbr
138
+ // 00000040 65 6c 6c 61 2f 64 65 76 65 6c 6f 70 2f 61 73 73 ella/develop/ass
139
+ // 00000050 65 74 73 2f 62 61 6e 6e 65 72 73 2f 74 68 69 6e ets/banners/thin
140
+ // 00000060 67 2d 75 6d g-um
141
+ ```
142
+
116
143
  ## Authors
117
144
 
118
145
  - [Karsten Schmidt](https://thi.ng)
package/index.d.ts CHANGED
@@ -166,6 +166,58 @@ export declare const U64LE: (x: ArrayLike<number>, i: number) => string;
166
166
  * @param i -
167
167
  */
168
168
  export declare const uuid: (id: ArrayLike<number>, i?: number) => string;
169
- export declare const hexdump: (bytes: Uint8Array | Uint8ClampedArray, addr: number, len: number, width?: number, ascii?: boolean) => string;
170
- export declare const hexdumpLines: (bytes: Uint8Array | Uint8ClampedArray, addr: number, len: number, width?: number, ascii?: boolean) => string[];
169
+ /**
170
+ * Takes a byte array, and optional start address, length and other opts.
171
+ * Produces a hexdump as string.
172
+ *
173
+ * @remarks
174
+ * Also see {@link printHexdump}, {@link hexdumpLines}.
175
+ *
176
+ * @example
177
+ * ```ts tangle:../export/hexdump.ts
178
+ * import { printHexdump } from "@thi.ng/hex";
179
+ *
180
+ * const bytes = new TextEncoder().encode("Hellö Wørld! 👋🤝🫶 ...so long!");
181
+ * printHexdump(bytes);
182
+ *
183
+ * // 00000000 48 65 6c 6c c3 b6 20 57 c3 b8 72 6c 64 21 20 f0 Hell.. W..rld! .
184
+ * // 00000010 9f 91 8b f0 9f a4 9d f0 9f ab b6 20 2e 2e 2e 73 ........... ...s
185
+ * // 00000020 6f 20 6c 6f 6e 67 21 o long!
186
+ * ```
187
+ *
188
+ * @param bytes
189
+ * @param addr
190
+ * @param len
191
+ * @param width
192
+ * @param ascii
193
+ */
194
+ export declare const hexdump: (bytes: Uint8Array | Uint8ClampedArray, addr?: number, len?: number, width?: number, ascii?: boolean) => string;
195
+ /**
196
+ * Syntax sugar for `console.log(hexdump(...))`.
197
+ *
198
+ * @param bytes
199
+ * @param addr
200
+ * @param len
201
+ * @param width
202
+ * @param ascii
203
+ */
204
+ export declare const printHexdump: (bytes: Uint8Array | Uint8ClampedArray, addr?: number, len?: number, width?: number, ascii?: boolean) => void;
205
+ /**
206
+ * Takes a byte array, and optional start address, length and other opts.
207
+ * Produces a hexdump as string array.
208
+ *
209
+ * @remarks
210
+ * The `width` arg specifies the number of bytes per line. The `ascii` flag
211
+ * indicates if the bytes of each row should also be formatted as ASCII in an
212
+ * additional column (non-printable ASCII values are represented as `.`).
213
+ *
214
+ * Also see {@link printHexdump}, {@link hexdumpLines}.
215
+ *
216
+ * @param bytes
217
+ * @param addr
218
+ * @param len
219
+ * @param width
220
+ * @param ascii
221
+ */
222
+ export declare const hexdumpLines: (bytes: Uint8Array | Uint8ClampedArray, addr?: number, len?: number, width?: number, ascii?: boolean) => string[];
171
223
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -26,7 +26,8 @@ const uuid = (id, i = 0) => (
26
26
  `${U32BE(id, i)}-${U16BE(id, i + 4)}-${U16BE(id, i + 6)}-${U16BE(id, i + 8)}-${U48BE(id, i + 10)}`
27
27
  );
28
28
  const hexdump = (bytes, addr, len, width, ascii) => hexdumpLines(bytes, addr, len, width, ascii).join("\n");
29
- const hexdumpLines = (bytes, addr, len, width = 16, ascii = true) => {
29
+ const printHexdump = (bytes, addr, len, width, ascii) => console.log(hexdump(bytes, addr, len, width, ascii));
30
+ const hexdumpLines = (bytes, addr = 0, len = bytes.length - addr, width = 16, ascii = true) => {
30
31
  len = Math.min(len, bytes.length - addr);
31
32
  let res = [];
32
33
  while (len > 0) {
@@ -72,5 +73,6 @@ export {
72
73
  U8A,
73
74
  hexdump,
74
75
  hexdumpLines,
76
+ printHexdump,
75
77
  uuid
76
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hex",
3
- "version": "2.3.85",
3
+ "version": "2.4.1",
4
4
  "description": "Hex string formatters for 4/8/16/24/32/48/64bit words, hexdump formatting of binary data",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -39,7 +39,7 @@
39
39
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
40
40
  },
41
41
  "devDependencies": {
42
- "esbuild": "^0.25.11",
42
+ "esbuild": "^0.27.0",
43
43
  "typedoc": "^0.28.14",
44
44
  "typescript": "^5.9.3"
45
45
  },
@@ -73,5 +73,5 @@
73
73
  ],
74
74
  "year": 2020
75
75
  },
76
- "gitHead": "d977f819bcafdcb2b24c45f8d01a167fe29fc85a\n"
76
+ "gitHead": "be6e7657b1e5c54d7d648d1b52888a7297e95a17\n"
77
77
  }