Skip to content

Commit

Permalink
feat(transducers-binary): add hexDumpString() syntax sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Feb 6, 2020
1 parent 6d658d0 commit a3ad805
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/transducers-binary/src/hex-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function hexDump(...args: any[]): any {
return comp(
padLast(cols, 0),
map(
juxt(U8, (x) => (x > 31 && x < 128 ? String.fromCharCode(x) : "."))
juxt(U8, (x) => (x > 31 && x < 127 ? String.fromCharCode(x) : "."))
),
partition(cols, true),
map(
Expand All @@ -60,3 +60,15 @@ export function hexDump(...args: any[]): any {
mapIndexed((i, [h, a]) => `${U32(address + i * cols)} | ${h} | ${a}`)
);
}

/**
* Convenience wrapper for {@link hexDump}, return the hexdump as a
* single result string.
*
* @param opts -
* @param src -
*/
export const hexDumpString = (
opts: Partial<HexDumpOpts>,
src: Iterable<number>
) => [...hexDump(opts, src)].join("\n");

0 comments on commit a3ad805

Please sign in to comment.