# generic-hex-dump

> Get individual lines of a typical hex dump

Latest version **1.2.0** (published 2015-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install generic-hex-dump
pnpm add generic-hex-dump
yarn add generic-hex-dump
bun add generic-hex-dump
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2015-10-27 |
| First published | 2015-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | juliangruber |

## Links

- npm: https://www.npmjs.com/package/generic-hex-dump
- Repository: https://github.com/juliangruber/generic-hex-dump
- Homepage: https://github.com/juliangruber/generic-hex-dump#readme
- Issues: https://github.com/juliangruber/generic-hex-dump/issues
- npm.io page: https://npm.io/package/generic-hex-dump

## Recent versions

- 1.2.0 (latest) — 2015-10-27
- 1.1.2 — 2015-10-08
- 1.1.1 — 2015-10-08
- 1.1.0 — 2015-10-08
- 1.0.0 — 2015-10-08

## README

# generic-hex-dump

  Get individual lines of a typical hex dump. Use this to implement your own interface or whatever else you want.

## Example

```js
var Dump = require('generic-hex-dump');

var buf = Buffer('abcdefghijklmnopqrstuvwxyz0123456789><\x00\x00');
var dump = new Dump(buf.length);

var lines = dump.lines();
for (var i = 0; i < lines; i++) {
  var slice = dump.slice(buf, i);
  console.log(
    dump.offset(i),
    dump.hex(slice).join(' '),
    dump.strings(slice).join('')
  );
}
```

Output:

```bash
$ node example.js
000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop
000010 71 72 73 74 75 76 77 78 79 7a 30 31 32 33 34 35 qrstuvwxyz012345
000020 36 37 38 39 3e 3c 00 00 6789><..
```

## Installation

```bash
$ npm install generic-hex-dump
```

## API

### Dump(length)

  Create a new dump for a buffer of total `length`.

### .lines()

  Get the number of lines the dump will have.

### .slice(buf, line)

  Get `buf`'s slice for `line`.

### .offset(line)

  Print the offset column for `line`.

### .hex(slice)

  Create an array of 2-character hex strings for each byte in `slice`.

### .strings(slice)

  Create an array of 1-character strings for each byte in `slice`, defaulting to `.` if a byte's value isn't human readable.

### .offsetWidth()

  Get the width of the offset column.

### .printable(v)

  Check if character code `v` is printable. Override this function to change what `.strings()` replaces with a `.`.

### .replace(from, to)

  In the string column, replace character `from` with `to`. Either can be a char code or a single character string. If this is defined for a character, the `.printable()` check will be bypassed.

  Example:
  
  Replace all occurences of `\r` with `␍`:

```js
  dump.replace('\r', '␍');
```

## License

  MIT

---
_Source: https://npm.io/package/generic-hex-dump · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
