@thi.ng/hex
Advanced tools
Comparing version 2.2.2 to 2.3.0
# Change Log | ||
- **Last updated**: 2022-10-28T19:08:39Z | ||
- **Last updated**: 2022-11-23T22:46:54Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -12,2 +12,9 @@ | ||
## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hex@2.3.0) (2022-11-23) | ||
#### 🚀 Features | ||
- add hexdump fns ([1b97845](https://github.com/thi-ng/umbrella/commit/1b97845)) | ||
- add hexdump() / hexdumpLines() | ||
## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hex@2.2.0) (2022-09-21) | ||
@@ -14,0 +21,0 @@ |
@@ -169,2 +169,4 @@ /** | ||
export declare const uuid: (id: ArrayLike<number>, i?: number) => string; | ||
export declare const hexdump: (bytes: Uint8Array | Uint8ClampedArray, addr: number, len: number, width?: number, ascii?: boolean) => string; | ||
export declare const hexdumpLines: (bytes: Uint8Array | Uint8ClampedArray, addr: number, len: number, width?: number, ascii?: boolean) => string[]; | ||
//# sourceMappingURL=index.d.ts.map |
20
index.js
@@ -172,1 +172,21 @@ const P32 = 0x100000000; | ||
`${U32BE(id, i)}-${U16BE(id, i + 4)}-${U16BE(id, i + 6)}-${U16BE(id, i + 8)}-${U48BE(id, i + 10)}`; | ||
export const hexdump = (bytes, addr, len, width, ascii) => hexdumpLines(bytes, addr, len, width, ascii).join("\n"); | ||
export const hexdumpLines = (bytes, addr, len, width = 16, ascii = true) => { | ||
len = Math.min(len, bytes.length - addr); | ||
let res = []; | ||
while (len > 0) { | ||
const row = [...bytes.subarray(addr, addr + Math.min(len, width))]; | ||
const pad = len < width && ascii ? new Array(width - len).fill(" ") : []; | ||
res.push([ | ||
U32(addr), | ||
...row.map(U8), | ||
...pad, | ||
row | ||
.map((x) => x >= 0x20 && x < 0x80 ? String.fromCharCode(x) : ".") | ||
.join(""), | ||
].join(" ")); | ||
addr += width; | ||
len -= width; | ||
} | ||
return res; | ||
}; |
{ | ||
"name": "@thi.ng/hex", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "Hex string formatters for 4/8/16/24/32/48/64bit words", | ||
@@ -38,6 +38,6 @@ "type": "module", | ||
"@microsoft/api-extractor": "^7.33.5", | ||
"@thi.ng/testament": "^0.3.4", | ||
"@thi.ng/testament": "^0.3.5", | ||
"rimraf": "^3.0.2", | ||
"tools": "^0.0.1", | ||
"typedoc": "^0.23.18", | ||
"typedoc": "^0.23.20", | ||
"typescript": "^4.8.4" | ||
@@ -59,4 +59,4 @@ }, | ||
"files": [ | ||
"*.js", | ||
"*.d.ts" | ||
"./*.js", | ||
"./*.d.ts" | ||
], | ||
@@ -74,3 +74,3 @@ "exports": { | ||
}, | ||
"gitHead": "41e59c7ad9bf24bb0230a5f60d05715e0fc1c1e6\n" | ||
"gitHead": "044ee6a3895720fc78e115032d4d831b63510929\n" | ||
} |
@@ -58,3 +58,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (gzipped, pre-treeshake): ESM: 405 bytes | ||
Package sizes (gzipped, pre-treeshake): ESM: 624 bytes | ||
@@ -61,0 +61,0 @@ ## Dependencies |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28423
361