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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@httpx/stable-hash

v0.3.7

Published

Create keys or hashes from javascript values, useful for memoization or cache key generation.

Downloads

1,086

Readme

@httpx/stable-hash

Create keys or hashes from javascript values, useful for memoization or cache key generation.

npm changelog codecov bundles node browserslist size downloads license

Install

$ npm install @httpx/stable-hash
$ yarn add @httpx/stable-hash
$ pnpm add @httpx/stable-hash

Features

  • 👉  Works with plain objects, dates, bigint, number, null, undefined and arrays.
  • 🦄  Insensitive to object keys or array parameters order.
  • 🙏  Properly error if it encounters an unsupported datatype.
  • 📐  Lightweight (starts at ~500B).
  • 🛡️  Tested on node 20-24, bun, browser, cloudflare workers and runtime/edge.
  • 🗝️  Available in ESM and CJS formats.

Documentation

👉 Official website or Github Readme

Usage

createStableKey

import { createStableKey } from '@httpx/stable-hash'

const params = {
  key8: 'a string',
  key1: 1,
  key3: true,
  key2: [3, 2, 1],
  key7: {
    key2: true,
    key1: new Date('2025-02-11T08:58:32.075Z'),
  },
};

const result = createStableKey(params);

if (!result.success) {
  throw result.error; // TypeError
}

const key = result.key;

// Key contains a json comptatible string with object keys sorted.
// By default it will sort arrays if they contains only strings or numbers
// including bigints.

// "{"key1":1,"key2":[1,2,3],"key3":true,"key7":{"key1":"2025-02-11T08:58:32.075Z","key2":true},"key8":"a string"}"

createStableKeyOrThrow

import { createStableKeyOrThrow } from '@httpx/stable-hash'

const params = {
  key8: 'a string',
  key1: 1,
  key3: true,
  key2: [3, 2, 1],
  key7: {
    key2: true,
    key1: new Date('2025-02-11T08:58:32.075Z'),
  },
};

const key = createStableKeyOrThrow(params);

// Key contains a json comptatible string with object keys sorted.
// By default it will sort arrays if they contains only strings or numbers
// including bigints.

// "{"key1":1,"key2":[1,2,3],"key3":true,"key7":{"key1":"2025-02-11T08:58:32.075Z","key2":true},"key8":"a string"}"

createStableHash

import { createStableHash } from '@httpx/stable-hash';

const value = {
  key8: 'a string',
  key1: 1,
  key3: true,
  key2: [3, 2, 1],
  key7: {
    key2: true,
    key1: new Date('2025-02-11T08:58:32.075Z'),
  },
};

const result = await createStableHash(value, {
  // By default SHA-256 is used (SHA-512 available)
  algorithm: 'SHA-256',
  // By default the hash is encoded in hexadecimal
  encoding: 'hexa',
});
if (!result.success) {
  throw result.error;
}
const hash = result.hash;
// -> 'fb17a6300efcf62ae80708e2a672aee581b7f0dd7c6a9a7a748218846c679394'

createStableHashOrThrow

import { createStableHashOrThrow } from '@httpx/stable-hash';

const params = {
  key8: 'a string',
  key1: 1,
  key3: true,
  key2: [3, 2, 1],
  key7: {
    key2: true,
    key1: new Date('2025-02-11T08:58:32.075Z'),
  },
};

try {
  const hash = await createStableHashOrThrow(params, {
    // By default SHA-256 is used (SHA-512 available)
    algorithm: 'SHA-256',
    // By default the hash is encoded in hexadecimal
    encoding: 'hexa',
  });
  // -> 'fb17a6300efcf62ae80708e2a672aee581b7f0dd7c6a9a7a748218846c679394'
} catch (e) {
  // TypeError in case of an unserializable data type
}

Alternatives

  • [x] stable-hash. Fastest alternative. Might swallow errors though.

Benchmarks

Performance is monitored with codspeed.io.

CodSpeed Badge

See bench for details.

Bundle size

Bundle size is tracked by a size-limit configuration

| Scenario | Size with deps (compressed) | |---------------------------------------------------------------|----------------------------:| | import { createStableKeyOrThrow } from '@httpx/stable-hash' | ~ 480B | | import { createStableKey } from '@httpx/stable-hash' | ~ 520B | | import { createStableHashOrThrow } from '@httpx/stable-hash' | ~ 650B | | import { createStableHash } from '@httpx/stable-hash' | ~ 695B |

Compatibility

| Level | CI | Description | |--------------|----|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Node | ✅ | CI for 20.x, 22.x, 24.x & 25.x. | | Browser | ✅ | Tested with latest chrome (vitest/playwright) | | Browserslist | ✅ | > 95% on 01/2025. defaults, chrome >= 96, firefox >= 105, edge >= 113, safari >= 15, ios >= 15, opera >= 103, not dead | | Bun | ✅ | Tested with latest (at time of writing >= 1.3.3) | | Edge | ✅ | Ensured on CI with @vercel/edge-runtime. | | Cloudflare | ✅ | Ensured with @cloudflare/vitest-pool-workers (see wrangler.toml | | Typescript | ✅ | TS 5.0 + / are-the-type-wrong checks on CI. | | ES2022 | ✅ | Dist files checked with es-check | | Performance | ✅ | Monitored with with codspeed.io |

For older browsers: most frontend frameworks can transpile the library (ie: nextjs...)

Benchmarks

Performance is continuously monitored thanks to codspeed.io.

CodSpeed Badge


 RUN  v3.0.5 /home/sebastien/github/httpx/packages/stable-hash


 ✓ bench/compare.bench.ts > Comparison 6441ms
     name                                       hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · @httpx/stable-hash                 294,773.22  0.0030  0.5363  0.0034  0.0032  0.0071  0.0094  0.0151  ±0.37%   147387   slowest
   · stable-hash                     13,291,407.61  0.0001  0.0766  0.0001  0.0001  0.0001  0.0001  0.0003  ±0.06%  6645705   fastest
   · @tanstack/query-core (hashKey)     295,851.66  0.0031  0.4376  0.0034  0.0033  0.0042  0.0059  0.0076  ±0.50%   147926

 ✓ bench/create-stable-hash.bench.ts > createStableHashOrThrow 1228ms
     name                                                  hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · createStableHashOrThrow with array sorting     29,048.08  0.0263  0.2879  0.0344  0.0336  0.0729  0.1158  0.1718  ±0.49%    14525
   · createStableHashOrThrow without array sorting  32,139.11  0.0245  0.9538  0.0311  0.0307  0.0459  0.0712  0.1496  ±0.55%    16070   fastest

 ✓ bench/create-stable-key.bench.ts > createStableKeyOrThrow 1403ms
     name                                                  hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · createStableKeyOrThrow with array sorting     203,266.13  0.0044  0.4635  0.0049  0.0048  0.0087  0.0091  0.0146  ±0.37%   101639
   · createStableKeyOrThrow without array sorting  283,858.83  0.0031  0.8852  0.0035  0.0034  0.0073  0.0095  0.0149  ±0.46%   141930   fastest

 BENCH  Summary

  stable-hash - bench/compare.bench.ts > Comparison
    44.93x faster than @tanstack/query-core (hashKey)
    45.09x faster than @httpx/stable-hash

  createStableHashOrThrow without array sorting - bench/create-stable-hash.bench.ts > createStableHashOrThrow
    1.11x faster than createStableHashOrThrow with array sorting

  createStableKeyOrThrow without array sorting - bench/create-stable-key.bench.ts > createStableKeyOrThrow
    1.40x faster than createStableKeyOrThrow with array sorting

See benchmark file for details.

Contributors

Contributions are warmly appreciated. Have a look to the CONTRIBUTING document.

Sponsors

If my OSS work brightens your day, let's take it to new heights together! Sponsor, coffee, or star – any gesture of support fuels my passion to improve. Thanks for being awesome! 🙏❤️

Special thanks to

License

MIT © Sébastien Vanvelthem and contributors.