# stable-id

> Generate 128bit hex id for stable JSON strigified object or string

Latest version **1.0.13** (published 2018-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install stable-id
pnpm add stable-id
yarn add stable-id
bun add stable-id
```

## 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.0.13 |
| Published | 2018-11-18 |
| First published | 2016-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ersun Warncke |
| Maintainers | ersun.warncke |

## Links

- npm: https://www.npmjs.com/package/stable-id
- Repository: https://github.com/warncke/stable-id
- Homepage: https://github.com/warncke/stable-id#readme
- Issues: https://github.com/warncke/stable-id/issues
- npm.io page: https://npm.io/package/stable-id

## Dependencies (1)

- [json-stable-stringify](https://npm.io/package/json-stable-stringify.md) 1.0.1

## Recent versions

- 1.0.13 (latest) — 2018-11-18
- 1.0.12 — 2018-01-15
- 1.0.11 — 2017-10-06
- 1.0.10 — 2017-10-04
- 1.0.9 — 2017-09-19
- 1.0.8 — 2017-09-10
- 1.0.7 — 2017-09-04
- 1.0.6 — 2017-08-05
- 1.0.5 — 2017-08-02
- 1.0.4 — 2017-07-27
- 1.0.3 — 2017-06-07
- 1.0.2 — 2017-06-06
- 1.0.1 — 2017-06-02
- 1.0.0 — 2017-05-29
- 0.2.4 — 2017-05-25
- … 8 more at https://npm.io/package/stable-id/versions

## README

# stable-id

Stable ID generates a 128-bit hex string id that is the first 128 bits of an
SHA-256 hash of the input data.

Objects are serialized using
[json-stable-stringify](https://www.npmjs.com/package/json-stable-stringify).

Errors will be thrown on objects that include circular references.

As of version 1.0.0 this string is lower case where previously it was upper
case.

## Stable id usage

    const stableId = require('stable-id')

    stableId(foo)

## Object stable id

    // 7a38bf81f383f69433ad6e900d35b3e2
    stableId({foo: 'bar'})

## String stable id

    // 2c26b46b68ffc68ff99b453c1d304134
    stableId('foo')

## Number stable id

    // 5feceb66ffc86f38d952786c6d696c79
    stableId(0)

    // 5feceb66ffc86f38d952786c6d696c79
    stableId('0')

Numbers are converted to strings so the stable id for a number will be the
same as the stable id of a string representation of the same number.

NaN and Infinity are not supported and return undefined.

## Boolean stable id

    // b5bea41b6c623f7c09f1bf24dcae58eb
    stableId(true)

    // b5bea41b6c623f7c09f1bf24dcae58eb
    stableId('true')

Booleans are converted to strings so the string true and the boolean true will
yield the same id.

## Infinity stable id

    // 78d9ce976067aaa5aa9024c17a726c9b
    stableId(Infinity)

    // 78d9ce976067aaa5aa9024c17a726c9b
    stableId('∞')

The number Infinity is converted to the U+221E unicode infinity character.

## Undefined id

    // undefined
    stableId(undefined)

    // undefined
    stableId(null)

    // undefined
    stableId(NaN)

undefined, null, and NaN all return an undefined id.

## Stable id with data

    var id = stableId({foo: 'bar'}, true)

    id.id   // 7a38bf81f383f69433ad6e900d35b3e2
    id.data // {"foo":"bar"}

When called with the second argument === true an object will be returned with
an `id` property which is the hex id and a `data` property which is the exact
string that was used to generate that id.

When storing data this method should be used to insure that the data stored
exactly matches the data that was used to create the id.

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