Zero-dependency JavaScript implementation of the MurmurHash2 algorithm for buffers.
MurmurHash2 is a fast, non-cryptographic hash useful for partitioning, caches, and lightweight checksums.
This library was originally inspired by Austin Appleby's work, flagUpDown/murmurhash-node, and CAV2's whitespace stripping.
npm install murmur2There are no production dependencies. The package ships index.js and TypeScript definitions in index.d.ts.
CommonJS:
const murmur2 = require("murmur2");ES modules (default import):
import murmur2 from "murmur2";TypeScript: types are bundled with the package. Use import murmur2 from "murmur2" with esModuleInterop, or require with export = interop.
Minimal example:
const removeWhitespaces = false;
const seed = 0;
const buffer = Buffer.from([1, 2, 3, 4]);
const hash = murmur2(buffer, seed, removeWhitespaces); // 1487941662Default export: a function murmur2(key, seed?, removeWhitespaces?).
| Parameter | Type | Default | Description |
|---|---|---|---|
key |
Buffer, Uint8Array, or array-like byte sequence |
(required) | Data to hash |
seed |
number |
0 |
Initial seed mixed into the hash |
removeWhitespaces |
boolean |
false |
When true, strips tab, LF, CR, and space bytes before hashing |
Returns: unsigned 32-bit integer (>>> 0).
- Gio Pavanelli - author and maintainer of the published package
Repository: callmeteus/murmur2
- Arzio - contributions to the algorithm and implementation
Issues and pull requests are welcome on GitHub.
Local development:
git clone https://github.com/callmeteus/murmur2.git
cd murmur2
npm install
npm testTests use node --test and require Node.js 18+. Runtime use of the package does not require that version; it applies only when running the test suite.
If you use Yarn in your workflow:
yarn testMIT - Copyright (c) Gio Pavanelli