Skip to content

Recoveredd/murmur-string-hash-kit

Repository files navigation

murmur-string-hash-kit

npm version License: MPL-2.0 CI

Small TypeScript helpers for deterministic MurmurHash3 x86_32 hashes of UTF-8 strings.

It is intended for browser-safe bucketing, cache keys, feature rollout buckets, fixture IDs, and non-cryptographic fingerprints. It has no runtime dependency and does not use Node-only APIs.

Demo

Try the browser preview: packages.wasta-wocket.fr/murmur-string-hash-kit.

Package quality

  • TypeScript types are generated from the source.
  • ESM-only package with no runtime dependencies.
  • Marked as side-effect free for bundlers.
  • CI runs npm ci, typecheck, build, and test.
  • Tested on Node.js 20 and 22 with GitHub Actions.
  • Browser-friendly implementation with no Node-only APIs.
import { hashString, hashStrings } from "murmur-string-hash-kit";

hashString("café", { seed: 42 });
// { value: 1990984759, hex: "76af9d77", base36: "wxux1z", seed: 42, bytes: 5 }

hashStrings(["alpha", "beta"], { seed: 7 });
// [{ input: "alpha", ... }, { input: "beta", ... }]

API

hashString(input, options?)

Returns a structured hash result:

  • value: unsigned 32-bit integer.
  • hex: zero-padded 8-character hexadecimal string.
  • base36: compact lowercase base36 string.
  • seed: normalized unsigned 32-bit seed.
  • bytes: UTF-8 byte length used for hashing.

Options:

  • seed: integer seed, default 0.
  • maxBytes: optional cap for untrusted input. No cap is applied by default.

hashStringToUint32(input, options?)

Returns only the unsigned 32-bit integer.

hashStringToHex(input, options?)

Returns only the zero-padded hexadecimal string.

hashStrings(inputs, options?)

Hashes many strings while preserving the original input beside each result.

Notes

This package implements only MurmurHash3 x86_32. It deliberately does not implement x64 or 128-bit variants, because the first draft targets the common browser-friendly string fingerprint case.

MurmurHash3 is not cryptographic. Do not use it for passwords, signatures, secrets, or adversarial integrity checks.

The implementation hashes UTF-8 bytes, not UTF-16 code units. It includes independent x86_32 vectors covering embedded nulls, endian-sensitive chunks, tail lengths, non-ASCII text, and long strings.

About

Hash UTF-8 strings with browser-friendly MurmurHash3 x86_32 helpers.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors