uniku
Reference

CUID v2

Non-sequential, string-native identifiers that resist enumeration.

CUID v2 is for public values where predictability is the problem. It is string-native, so there is no byte codec to maintain or expose.

import { cuidv2 } from 'uniku/cuid/v2'

const inviteId = cuidv2()
// 'rqa97fgr3wexenbnth08ihdk' (string)

Generated API reference

Public methods

Read source

Generate a CUID v2 string. CUID v2 is a secure, collision-resistant identifier that hashes multiple entropy sources using SHA3-512. Unlike time-ordered IDs (ULID, UUID v7), CUID v2 prevents enumeration attacks by making IDs non-predictable. Note: CUID v2 does not provide toBytes/fromBytes because it is a string-native format with no canonical binary representation (unlike UUID's 16-byte format).

cuidv2

Generate a CUID v2 string.

cuidv2(options?: Cuid2Options): string

Cuid2Options

length?

Length of the generated ID (2-32 characters). Default: 24

number
random?

Custom random bytes for deterministic testing. Must be at least 1 byte. For adequate entropy, use at least 16 bytes. Note: The fingerprint always uses cryptographically secure random bytes, regardless of this option.

Uint8Array
Examplecuidv2()// => 'rqa97fgr3wexenbnth08ihdk'
isValid

Return whether a value is a syntactically valid CUID v2 string.

isValid(id: unknown): id is string
Examplecuidv2.isValid('rqa97fgr3wexenbnth08ihdk')// => true