Skip to main content

Module id_gen

Module id_gen 

Source
Expand description

First-class ID type generation and validation.

Supports: UUID v4, UUID v7, ULID, CUID2, NanoID.

All IDs are represented as strings for JSON compatibility. UUID v7 and ULID are time-sortable (lexicographic order = chronological order).

Functionsยง

cuid2
Generate a CUID2 (Collision-resistant Unique Identifier v2).
cuid2_with_length
Generate a CUID2 with custom length (min 4, max 64).
detect_id_type
Detect the type of a string ID.
generate_by_type
Generate an ID by type name.
is_cuid2
Validate whether a string looks like a CUID2 (starts with letter, alphanumeric).
is_nanoid
Validate whether a string looks like a NanoID (URL-safe characters, reasonable length).
is_ulid
Validate whether a string is a valid ULID.
is_uuid
Validate whether a string is a valid UUID (any version).
nanoid
Generate a NanoID (URL-friendly unique string identifier).
nanoid_with_length
Generate a NanoID with custom length.
ulid
Generate a ULID (Universally Unique Lexicographically Sortable Identifier).
ulid_timestamp_ms
Extract the millisecond timestamp from a ULID.
uuid_v4
Generate a random UUID v4 (128-bit, not time-sortable).
uuid_v7
Generate a time-sorted UUID v7 (128-bit, time-sortable).
uuid_version
Extract the version from a UUID string (1-7, or 0 if invalid).