@kikuchan/hexdump
v0.1.0-alpha.9
Published
hexdump
Readme
@kikuchan/hexdump
Tiny, configurable hex dump utility for Node.js and browsers.
Install
npm install -D @kikuchan/hexdumpUsage
import { hexdump } from '@kikuchan/hexdump';
const bytes = Uint8Array.from([
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
]);
hexdump.log(bytes);output:
00000000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
00000010: | |API
Basic Functions
hexdump.log|warn|error(data, options?): outputs toconsole.log|warn|errorrespectively.hexdump(data, options?): returns the full string instead of printing.hexdump.create(printer): returns a hexdump function that prints toprinter(a function that takes a string).
data
- Binary-like data:
Uint8Array,Uint8ClampedArray,ArrayBufferLikeorDataView;
options?
addrOffset: number— Starting address for the first byte. Default0.addrLength: number— Hex digits shown for the address. Default8 - prefix.length(clamped to>= 0).prefix: string— Printed before the address (e.g."0x"). Default"".foldSize: number— Bytes per row. Default16.printChars: boolean— Show the ASCII gutter at right. Defaulttrue.footer: boolean— Print a trailing line showing the next address. Defaulttrue.color: boolean | 'simple' | 'html' | ((s: string, ctx: Context) => ColorizerOperation | undefined)—trueor'simple': add ANSI colors in terminals.'html': wrap parts with semantic spans likehexdump-address,hexdump-ascii, etc., and escape content.
printer?: (line: string) => void | null— Provide a per-line sink directly in options. Set tonullto disable printing even if a default printer is configured.formatter: (s: string, ctx: Context) => string | undefined— Transform each fragment before it is appended. Returnundefinedto drop that fragment.
