Nanoid
Compact, URL-safe random strings with configurable length and alphabet.
Nanoid is the compact choice for short URLs, invite codes, and session tokens. Its default alphabet is URL-safe; pass a length or options only when the boundary needs a different shape.
import { nanoid } from 'uniku/nanoid'
const inviteCode = nanoid()
// 'tCDaBJOIwLpjLMxN_DYdU' (string)nanoid.isValid() validates the default alphabet, not values generated with a custom alphabet.
Generated API reference
Public methods
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
- nanoid
Generate a Nanoid with the default URL-safe alphabet and 21-character length.
nanoid(): stringGenerate a Nanoid with the default alphabet and a custom length.
nanoid(size: number): stringGenerate a Nanoid with a custom alphabet, length, or deterministic random bytes.
nanoid(options: NanoidOptions): stringExamplenanoid()// => 'tCDaBJOIwLpjLMxN_DYdU'- isValid
Validate a nanoid string against the default URL-safe alphabet. Note: Does not validate IDs generated with custom alphabets.
isValid(id: unknown): id is stringExamplenanoid.isValid('tCDaBJOIwLpjLMxN_DYdU')// => true