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

compact-hash

v0.1.0

Published

Strip every whitespace character from a string, then hash the result (MurmurHash3 32-bit).

Downloads

16

Readme

compact-hash

Strip every whitespace character from a string, then hash the rest with a hash function of your choice.

  • Default hash: MurmurHash3 x86 32-bit — fast, well-distributed, non-cryptographic. Zero runtime dependencies.
  • Pluggable: pass any (string) => string closure (sha256, xxhash, blake3, …) to swap algorithms without pulling in another lib here.
  • Sync API, works in Node and the browser. Dual ESM + CJS build with TypeScript types.

Install

npm install compact-hash
# or
pnpm add compact-hash

Usage

import { compactHash } from 'compact-hash';

// Default: MurmurHash3 32-bit → 8-char hex
compactHash('hello world'); // 'a03719ca'

// Inputs that differ only in whitespace collapse to the same digest:
compactHash('hello world')    === compactHash('helloworld');  // true
compactHash('hello\n\tworld') === compactHash('hello world'); // true
compactHash('你好  世界')      === compactHash('你好世界');     // true

Plug in a different hash

compactHash takes an optional hash: (s: string) => string closure. Anything that hashes a string to a string works.

import { compactHash } from 'compact-hash';
import { createHash } from 'node:crypto';

// Node's built-in sha256
const sha256 = (s: string) => createHash('sha256').update(s).digest('hex');
compactHash('hello world', sha256);
// → '936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af'

// xxhash-wasm (after `await xxhash()`):
const xxhasher = await xxhash();
compactHash('hello world', (s) => xxhasher.h64ToString(s));

// Your own keyed/scoped variant:
compactHash('hello world', (s) => myHmac(s, 'some-key'));

Seeded MurmurHash3

import { compactHash, murmurHashWithSeed } from 'compact-hash';

compactHash('hello world', murmurHashWithSeed(42));

API

compactHash(input: string, hash?: HashFn): string

Strips characters matched by JS \s (ASCII whitespace plus Unicode whitespace like NBSP, em-space, ideographic space), then calls hash on what remains.

  • hash defaults to murmurHash (MurmurHash3 32-bit, 8-char hex).
  • Returns whatever hash returns, unchanged.

type HashFn = (input: string) => string

murmurHash: HashFn

Default MurmurHash3 hasher (seed 0).

murmurHashWithSeed(seed: number): HashFn

MurmurHash3 hasher with a custom 32-bit seed.

murmur3_32(bytes: Uint8Array, seed?: number): number

murmur3_32Hex(bytes: Uint8Array, seed?: number): string

Raw byte-level API in case you want to hash arbitrary bytes without the whitespace-strip step.

Notes on the default algorithm

MurmurHash3 is not cryptographically secure — never use it for password hashing, signatures, or anywhere an adversary can craft collisions. It's designed for fast content fingerprinting, hash tables, and dedup. The 32-bit default reaches ~50% collision probability around 77k random inputs (birthday paradox over 2³²); fine for most fingerprint workloads. Swap in sha256 (or any other hash) via the closure parameter when you need stronger guarantees.

License

MIT