05h
v1.0.0
Published
Stable 32-bit string hash (FNV-1a) with a bucketing helper. Zero dependencies.
Maintainers
Readme
05h
Stable 32-bit string hash (FNV-1a) with a bucketing helper. Zero dependencies.
Same input always yields the same unsigned 32-bit integer on every platform and every Node version — suitable for stable sharding, cache keys and reproducible (seeded) ordering.
const hash = require('05h');
hash('hello'); // 1335831723
hash('hello'); // 1335831723 (always the same)
hash('hello', 100); // 23 (in [0, 100))
hash.bucket('id', 8); // 0..7 (shard index)API
hash(value, modulo?)
| Argument | Type | Description |
|---|---|---|
| value | string | Input. Non-strings are coerced with String(). |
| modulo | number? | When given, the result is reduced into [0, modulo). Invalid moduli are ignored. |
Returns an unsigned 32-bit number.
hash.bucket(value, buckets)
Convenience wrapper returning a stable index in [0, buckets).
Notes
Not a cryptographic hash — do not use it for security purposes.
License
MIT
