/** * Short, deterministic non-cryptographic hashing and id minting. * * {@link fnvHash} / {@link fnvHashWithOptions} produce a stable FNV-1a * digest over arbitrary structured input; {@link toBase32} encodes a * 32-bit integer compactly; {@link id} mints v4 UUIDs (or short hex * slices). All browser-safe - built on `globalThis.crypto`, no * `node:crypto` import. **Never** use these for tokens, signatures, or * anything an attacker shouldn't be able to forge. * * @module */ /** * Mint a v4 UUID, or a short hex slice of one when `length` is set. * * - `id()` returns a full RFC 4122 v4 UUID. Pick this when global * uniqueness matters: long-running batches, ids that cross a storage / * process boundary, anything that may collide across machines. * - `id(length)` returns the first `length` hex chars of a fresh UUID * with dashes stripped (e.g. `id(8) -> "a3f1c92b"`). Pick this when the * id has to be short / typeable and the scope is bounded - cache keys * local to a request, slug suffixes. `length <= 0` throws. * * Prefers `crypto.randomUUID()`, which covers Node (>= 19) and a browser on * a secure origin. Browsers gate `randomUUID` behind a secure context, so a * page served over plain http (a LAN dev host) has `crypto` but not that * method; this package is browser-safe and its callers mint ids on the * render path, so it degrades instead of throwing: `getRandomValues` when * present, else `Math.random`. Every branch returns a well-formed v4 UUID - * only the entropy source differs. * * @example * id(); // "123e4567-e89b-12d3-a456-426614174000" * id(8); // "a3f1c92b" */ export declare function id(length?: number): string; /** * Short, deterministic FNV-1a hash over one or more values. Wraps * {@link fnvHashWithOptions} with all defaults: 6-char Crockford-style * base-32 output (digits + lowercase, minus `i`/`l`/`o`/`u`). * Browser-safe (no `node:crypto`). * * Accepts any mix of primitives, arrays, plain objects, `Map`s, and * `Set`s; nested structures are walked deterministically so the hash is * order-stable for objects / maps / sets and order-sensitive for arrays. * Cycles are detected and folded into a `circular:` marker. * * Use for cache keys, slug suffixes, log correlation ids, and other * "give me something short and stable" needs - **never** for tokens or * signatures. FNV-1a is a non-cryptographic hash. * * @example * fnvHash("databricks-claude-sonnet-4-6"); // "k3p9q7" * fnvHash([1, 2, 3]) !== fnvHash([3, 2, 1]); */ export declare function fnvHash(...values: unknown[]): string; /** * Configurable counterpart to {@link 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. * * @example * fnvHashWithOptions({ length: 4 }, "user@example.com"); // 4 chars * fnvHashWithOptions({ digest: nsHash }, key) !== fnvHash(key); // namespaced */ export declare function fnvHashWithOptions(options?: { length?: number; alphabet?: string; digest?: number; }, ...values: unknown[]): 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. * * @example * toBase32(0); // "0" * toBase32(31); // "z" * toBase32(0xdeadbe); // "6vmtw" */ export declare function toBase32(value: number, alphabet?: string, disableAlphabetValidation?: boolean): string;