Configure custom alphabets using `digits` and `intDigits`
mainYou can customize the character sets used for generating keys.
The digits alphabet
Controls the digit values of a key. Defaults to BASE_62_DIGITS (0-9A-Za-z).
Requirements:
- Must be single-byte (ASCII/Latin-1, not multi-byte like Greek).
- Must be sorted in ascending character-code order with no duplicates.
The intDigits alphabet (Integer Heads)
Every key starts with a 'head' (a magnitude/length marker) drawn from intDigits. The alphabet is split in half: the first half are negative-length heads, the second half are positive-length heads. It must have an even length.
Behavior Patterns
- Self-headed (Default): If you provide
digitsbut omitintDigits,intDigitsdefaults todigits. This is useful for custom bases like base-10. - Classic Latin Heads: If you omit
digitsentirely,intDigitsdefaults toBASE_52_DIGITS(A-Zfor negative,a-zfor positive). This produces the classic format (e.g.,a0,Z9). - Hybrid: To use a custom
digitsalphabet while keeping classic Latin heads, passBASE_52_DIGITSexplicitly as theintDigitsargument.
import { generateNKeysBetween, BASE_52_DIGITS } from "fractional-indexing";
// self-headed (intDigits defaults to digits):
generateNKeysBetween(null, null, 4, "0123456789"); // ["50", "51", "52", "53"]
// Latin heads (intDigits set explicitly):
generateNKeysBetween(null, null, 4, "0123456789", BASE_52_DIGITS); // ["a0", "a1", "a2", "a3"]