Skip to content

Function: fnvHashWithOptions()

fnvHashWithOptions(options?, …values): string

Configurable counterpart to fnvHash.

Options:

  • length (default 6): number of base-32 chars to return. Capped at 7 - the underlying digest is 32 bits, which base-32-encodes to at most 7 chars. Output is left-padded with the alphabet’s zero character so short digests still hit the requested width.
  • alphabet (default Crockford-style "0123456789abcdefghjkmnpqrstvwxyz"): 32 distinct characters used to encode the digest. Throws when not exactly 32 unique chars.
  • digest (default 0x811c9dc5, the FNV-1a offset basis): the seed the running digest starts from. Useful for namespacing so otherwise-identical inputs hashed under different namespaces never collide, and for chaining hashes across pipeline stages.

The hash is not stable across changes to the alphabet or length - those tune the output, not the digest input.

string

number

number

unknown[]

string

fnvHashWithOptions({ length: 4 }, "user@example.com"); // 4 chars
fnvHashWithOptions({ digest: nsHash }, key) !== fnvHash(key); // namespaced