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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ohash

v2.0.11

Published

Simple object hashing, serialization and comparison utils.

Readme

#️ ohash

npm version npm downloads bundle size codecov

Simple object hashing, serialization and comparison utils.

[!NOTE] You are on active v2 development branch. Check v1 for old ohash v1 docs and release notes for migration.

Usage

Install ohash:

# ✨ Auto-detect (npm, yarn, pnpm, bun or deno)
npx nypm i ohash

Import:

// ESM import
import { hash, serialize, digest, isEqual } from "ohash";
import { diff } from "ohash/utils";

// Dynamic import
const { hash, serialize, digest, isEqual } = await import("ohash");
const { diff } = await import("ohash/utils");
import { hash, serialize, digest, isEqual } from "https://esm.sh/ohash";
import { diff } from "https://esm.sh/ohash/utils";

// Dynamic import
const { hash, serialize, digest, isEqual } = await import(
  "https://esm.sh/ohash"
);
const { diff } = await import("https://esm.sh/ohash/utils");

hash(input)

Hashes any JS value into a string.

The input is first serialized then it is hashed.

import { hash } from "ohash";

// "g82Nh7Lh3CURFX9zCBhc5xgU0K7L0V1qkoHyRsKNqA4"
console.log(hash({ foo: "bar" }));

serialize(input)

Serializes any input value into a string for hashing.

[!IMPORTANT] > serialize method uses best efforts to generate stable serialized values; however, it is not designed for security purposes. Keep in mind that there is always a chance of intentional collisions caused by user input.

import { serialize } from "ohash";

// "{foo:'bar'}"
console.log(serialize({ foo: "bar" }));

digest(str)

Hashes a string using the SHA-256 algorithm and encodes it in Base64URL format.

import { digest } from "ohash";

// "f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk"
console.log(digest("Hello World!"));

isEqual(obj1, obj2)

Compare two objects using === and then fallbacks to compare based on their serialized values.

import { isEqual } from "ohash";

// true
console.log(isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }));

diff(obj1, obj2)

Compare two objects with nested serialization. Returns an array of changes.

The returned value is an array of diff entries with $key, $hash, $value, and $props. When logging, a string version of the changelog is displayed.

import { diff } from "ohash/utils";

const createObject = () => ({
  foo: "bar",
  nested: {
    y: 123,
    bar: {
      baz: "123",
    },
  },
});

const obj1 = createObject();
const obj2 = createObject();

obj2.nested.x = 123;
delete obj2.nested.y;
obj2.nested.bar.baz = 123;

const diff = diff(obj1, obj2);

// [-] Removed nested.y
// [~] Changed nested.bar.baz from "123" to 123
// [+] Added   nested.x
console.log(diff(obj1, obj2));

Contribute

  • Clone this repository
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛 Published under MIT License.

Object serialization originally based on puleos/object-hash by Scott Puleo.

sha256 implementation originally based on brix/crypto-js.