@thi.ng/hex 2.2.2 → 2.3.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-10-28T19:08:39Z
3
+ - **Last updated**: 2022-11-23T22:46:54Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hex@2.3.0) (2022-11-23)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add hexdump fns ([1b97845](https://github.com/thi-ng/umbrella/commit/1b97845))
17
+ - add hexdump() / hexdumpLines()
18
+
12
19
  ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hex@2.2.0) (2022-09-21)
13
20
 
14
21
  #### 🚀 Features
package/README.md CHANGED
@@ -55,7 +55,7 @@ node --experimental-repl-await
55
55
  > const hex = await import("@thi.ng/hex");
56
56
  ```
57
57
 
58
- Package sizes (gzipped, pre-treeshake): ESM: 405 bytes
58
+ Package sizes (gzipped, pre-treeshake): ESM: 624 bytes
59
59
 
60
60
  ## Dependencies
61
61
 
package/index.d.ts CHANGED
@@ -166,4 +166,6 @@ 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
171
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -169,3 +169,23 @@ export const U64LE = (x, i) => U32LE(x, i + 4) + U32LE(x, i);
169
169
  export const uuid = (id, i = 0) =>
170
170
  // prettier-ignore
171
171
  `${U32BE(id, i)}-${U16BE(id, i + 4)}-${U16BE(id, i + 6)}-${U16BE(id, i + 8)}-${U48BE(id, i + 10)}`;
172
+ export const hexdump = (bytes, addr, len, width, ascii) => hexdumpLines(bytes, addr, len, width, ascii).join("\n");
173
+ export const hexdumpLines = (bytes, addr, len, width = 16, ascii = true) => {
174
+ len = Math.min(len, bytes.length - addr);
175
+ let res = [];
176
+ while (len > 0) {
177
+ const row = [...bytes.subarray(addr, addr + Math.min(len, width))];
178
+ const pad = len < width && ascii ? new Array(width - len).fill(" ") : [];
179
+ res.push([
180
+ U32(addr),
181
+ ...row.map(U8),
182
+ ...pad,
183
+ row
184
+ .map((x) => x >= 0x20 && x < 0x80 ? String.fromCharCode(x) : ".")
185
+ .join(""),
186
+ ].join(" "));
187
+ addr += width;
188
+ len -= width;
189
+ }
190
+ return res;
191
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hex",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "Hex string formatters for 4/8/16/24/32/48/64bit words",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@microsoft/api-extractor": "^7.33.5",
38
- "@thi.ng/testament": "^0.3.4",
38
+ "@thi.ng/testament": "^0.3.5",
39
39
  "rimraf": "^3.0.2",
40
40
  "tools": "^0.0.1",
41
- "typedoc": "^0.23.18",
41
+ "typedoc": "^0.23.20",
42
42
  "typescript": "^4.8.4"
43
43
  },
44
44
  "keywords": [
@@ -55,8 +55,8 @@
55
55
  "node": ">=12.7"
56
56
  },
57
57
  "files": [
58
- "*.js",
59
- "*.d.ts"
58
+ "./*.js",
59
+ "./*.d.ts"
60
60
  ],
61
61
  "exports": {
62
62
  ".": {
@@ -69,5 +69,5 @@
69
69
  ],
70
70
  "year": 2020
71
71
  },
72
- "gitHead": "41e59c7ad9bf24bb0230a5f60d05715e0fc1c1e6\n"
72
+ "gitHead": "044ee6a3895720fc78e115032d4d831b63510929\n"
73
73
  }