Function: toBase32()
toBase32(
value,alphabet?,disableAlphabetValidation?):string
Encode a 32-bit unsigned integer as base-32 using the default
Crockford-style alphabet (or alphabet when provided). The encoding
has no zero-padding by default - toBase32(0) returns the
alphabet’s zero character, otherwise the result is the minimal number
of digits that fits the value. Pad / truncate at the call site when you
need a fixed width.
disableAlphabetValidation skips the unique-32-char check for hot
paths that have already validated the alphabet. The function still
requires alphabet.length === 32 either way.
Parameters
Section titled “Parameters”number
alphabet?
Section titled “alphabet?”string
disableAlphabetValidation?
Section titled “disableAlphabetValidation?”boolean
Returns
Section titled “Returns”string
Example
Section titled “Example”toBase32(0); // "0"toBase32(31); // "z"toBase32(0xdeadbe); // "6vmtw"