Registry / serialization / murmur-32

murmur-32

JSON →
library1.0.0jsnpmunverified

murmur-32 provides a JavaScript implementation of the MurmurHash3 algorithm for x86 32-bit systems. It's a non-cryptographic hash function known for its speed and good distribution properties, often used in hash tables, Bloom filters, and other data structures where collision resistance is less critical than performance. The current stable version is 1.0.0, released in July 2021. The package maintains a relatively slow release cadence, primarily focusing on stability and adherence to modern JavaScript standards. A key differentiator is its straightforward API for hashing both `ArrayBuffer` and string inputs, with strings being UTF-8 encoded by default since version 0.2.0, providing predictable cross-platform behavior.

npm install murmur-32
INSTALL
IMPORT
SIG · MURMUR-32
M
murmur-32
serializationjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

murmur32
import murmur32 from 'murmur-32'
const murmur32 = require('murmur-32')
The package converted to an ECMAScript module (ESM) in v1.0.0, dropping CommonJS support. Node.js version 12.20.0, 14.13.1, or >=16.0.0 is required.

Demonstrates how to compute a 32-bit MurmurHash3 for both string and ArrayBuffer inputs, and how to extract the integer hash value from the returned ArrayBuffer.

import murmur32 from 'murmur-32'; // Example 1: Hashing a string const stringKey = 'hello world'; const stringHashBuffer = murmur32(stringKey); const stringHashValue = new DataView(stringHashBuffer).getUint32(0, true); // Get 32-bit integer, little-endian console.log(`Hash for "${stringKey}": ${stringHashValue.toString(16).padStart(8, '0')}`); // Example 2: Hashing an ArrayBuffer const arrayBufferKey = new TextEncoder().encode('another example').buffer; const arrayBufferHashBuffer = murmur32(arrayBufferKey); const arrayBufferHashValue = new DataView(arrayBufferHashBuffer).getUint32(0, true); console.log(`Hash for "another example" (ArrayBuffer): ${arrayBufferHashValue.toString(16).padStart(8, '0')}`); // The function returns an ArrayBuffer of 4 bytes (32-bit hash). // You often need to convert it to an integer for practical use.
Debug
Known issues
breakingVersion 1.0.0 converted the package to an ECMAScript Module (ESM) and dropped CommonJS support. Direct `require()` statements will no longer work, and older Node.js versions are unsupported.
fix
Update your import statements from `const murmur32 = require('murmur-32')` to `import murmur32 from 'murmur-32'`. Ensure your Node.js environment is at least 12.20.0, 14.13.1, or 16.0.0+.
affects: >=1.0.0
breakingVersion 0.2.0 changed the default string encoding from UCS-2 (UTF-16) to UTF-8. If your application was implicitly relying on UCS-2 encoding for string inputs prior to v0.2.0, hash outputs for the same string inputs will now differ.
fix
If you need to maintain the exact hash values produced by older versions for string inputs, use the `array-buffer-from-string` package to explicitly convert your strings to UCS-2 encoded ArrayBuffers before passing them to `murmur32`. Otherwise, update any stored hash values or tests to reflect the new UTF-8 encoding behavior.
affects: >=0.2.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` to import `murmur-32` in a modern Node.js or browser ESM context after upgrading to version 1.0.0 or later.
fix
Change your import statement to `import murmur32 from 'murmur-32';`.
Hash mismatch for string inputs after upgrade
Upgrading from `murmur-32` v0.1.0 to v0.2.0 or later, where the string encoding for hash inputs changed from UCS-2 to UTF-8, resulting in different hash values for the same string.
fix
If you require the previous UCS-2 encoding behavior, pre-process your string inputs using `array-buffer-from-string`: `import arrayBufferFromString from 'array-buffer-from-string'; murmur32(arrayBufferFromString(yourString, 'ucs2'))`. Otherwise, update your application to expect UTF-8 encoded hash outputs.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
array-buffer-from-stringoptionalRequired for migrating applications from v0.1.0 to v0.2.0 or later if string keys were previously expected to be UCS-2 encoded and that behavior needs to be preserved. This is not a direct runtime dependency but a utility for managing a breaking change.
Agent activity
2 hits · last 30 days
node
2
Resources
murmur-32 — npm install murmur-32 · libregistry