{"id":11368,"library":"murmur-32","title":"MurmurHash3 32-bit","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/LinusU/murmur-32","tags":["javascript","digest","fast","hash","murmur hash","murmur","murmur3","murmurhash","murmurhash3"],"install":[{"cmd":"npm install murmur-32","lang":"bash","label":"npm"},{"cmd":"yarn add murmur-32","lang":"bash","label":"yarn"},{"cmd":"pnpm add murmur-32","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required 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.","package":"array-buffer-from-string","optional":true}],"imports":[{"note":"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.","wrong":"const murmur32 = require('murmur-32')","symbol":"murmur32","correct":"import murmur32 from 'murmur-32'"}],"quickstart":{"code":"import murmur32 from 'murmur-32';\n\n// Example 1: Hashing a string\nconst stringKey = 'hello world';\nconst stringHashBuffer = murmur32(stringKey);\nconst stringHashValue = new DataView(stringHashBuffer).getUint32(0, true); // Get 32-bit integer, little-endian\n\nconsole.log(`Hash for \"${stringKey}\": ${stringHashValue.toString(16).padStart(8, '0')}`);\n\n// Example 2: Hashing an ArrayBuffer\nconst arrayBufferKey = new TextEncoder().encode('another example').buffer;\nconst arrayBufferHashBuffer = murmur32(arrayBufferKey);\nconst arrayBufferHashValue = new DataView(arrayBufferHashBuffer).getUint32(0, true);\n\nconsole.log(`Hash for \"another example\" (ArrayBuffer): ${arrayBufferHashValue.toString(16).padStart(8, '0')}`);\n\n// The function returns an ArrayBuffer of 4 bytes (32-bit hash).\n// You often need to convert it to an integer for practical use.","lang":"javascript","description":"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."},"warnings":[{"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+.","message":"Version 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement to `import murmur32 from 'murmur-32';`.","cause":"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.","error":"ReferenceError: require is not defined"},{"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.","cause":"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.","error":"Hash mismatch for string inputs after upgrade"}],"ecosystem":"npm"}