npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stable-id

v1.0.13

Published

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

Downloads

65

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.

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.