CUID2 is the next generation of the CUID identifier standard. It is engineered specifically for horizontal scaling in distributed cloud applications where sequential guessing or timestamp disclosure is a security vulnerability.
Key Properties
- Starts with a letter: Always begins with a lowercase letter (
a-z), making it safely usable as HTML DOM IDs, CSS selectors, and JavaScript object keys. - Anti-Guessing Security: Uses non-sequential hashing (FNV-1a) over high-entropy cryptographic PRNG buffers, process counters, and millisecond time to ensure IDs are unpredictable.
- Adjustable Length: Supports generating IDs from short (8 chars) to long (32+ chars), defaulting to 24 characters.
Usage
js
import { cuid2 } from '@readytools/id';
// Standard 24-character CUID2
const id = cuid2();
// Returns: "tz4a98xxat96iws9zmbrgj3a"
// Custom length CUID2 (e.g. 32 characters)
const longId = cuid2(32);
// Returns: "k7n2m9px8q1w3v5t4r6y8u0o2i4e6a8s"⚡ Live Playground
cuid2()
Generating...
📏 Calculating...✨ Web Crypto Native