import { InvalidInputError, UniqueIdError } from "../errors.mjs"; //#region src/nanoid/nanoid.d.ts /** Default URL-safe alphabet (64 characters): A-Z, a-z, 0-9, underscore, hyphen */ declare const URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"; type NanoidOptions = { /** * Random bytes for deterministic output (testing). * For power-of-2 alphabets (2, 4, 8, 16, 32, 64, 128, 256): exactly `size` bytes needed. * For other alphabets: ~size * 2 bytes needed (rejection sampling). */ random?: Uint8Array; /** * Custom alphabet to use. Default: URL-safe A-Za-z0-9_- * Must be 2-256 printable ASCII characters (32-126) with no duplicates. */ alphabet?: string; /** * Length of generated ID. Default: 21. Maximum: 2048. */ size?: number; }; type Nanoid = { /** Generate nanoid with default settings */ (): string; /** Generate nanoid with custom size */ (size: number): string; /** Generate nanoid with options */ (options: NanoidOptions): string; /** * Validate a nanoid string against the default URL-safe alphabet. * Note: Does not validate IDs generated with custom alphabets. */ isValid(id: unknown): id is string; }; /** * Generate a URL-friendly unique string ID. * * Nanoid is a tiny, secure, URL-friendly unique string ID generator. * It uses a URL-safe alphabet (A-Za-z0-9_-) and generates 21-character * IDs by default with 126 bits of entropy. * * Unlike UUID v7 or ULID, nanoid is NOT time-ordered. Use it for: * - URL shorteners * - Session tokens * - Invite codes * - Any case where you need short, random IDs * * @example Basic usage * ```ts * import { nanoid } from 'uniku/nanoid' * * const id = nanoid() * // => "V1StGXR8_Z5jdHi6B-myT" * ``` * * @example Custom size * ```ts * const shortId = nanoid(10) * // => "IRFa-VaY2b" * ``` * * @example Custom alphabet (hex) * ```ts * const hexId = nanoid({ alphabet: '0123456789abcdef', size: 12 }) * // => "4f90d13a42bc" * ``` * * @example Validation * ```ts * const maybeId: unknown = getUserInput() * if (nanoid.isValid(maybeId)) { * // TypeScript knows maybeId is string * console.log(maybeId.length) * } * ``` * * @throws {InvalidInputError} Size must be between 0 and 2048 * @throws {InvalidInputError} Alphabet must contain 2-256 unique printable ASCII characters * @throws {InvalidInputError} Insufficient random bytes for requested size */ declare const nanoid: Nanoid; //#endregion export { InvalidInputError, Nanoid, NanoidOptions, URL_ALPHABET, UniqueIdError, nanoid }; //# sourceMappingURL=nanoid.d.mts.map