Skip to main content
Generate and validate globally unique identifiers including UUID v4 and ULID (Universally Unique Lexicographically Sortable Identifier).

Installation

UUID v4

Generate and work with UUID version 4 identifiers.

generateUuid4

Generates a new UUID v4 string.

isUuid4Valid

Checks if a string is a valid UUID v4.

getUuid4Bytes

Returns the byte array representation of a UUID v4 string.

makeUuid4FromBytes

Constructs a UUID v4 string from a byte array.

UUID constants

ULID

ULID (Universally Unique Lexicographically Sortable Identifier) combines the benefits of UUIDs with lexicographical sorting.
ULIDs are 26 characters long and encode a timestamp, making them naturally sortable by creation time.

generateUlid

Generates a new ULID string.

generateUlidList

Generates multiple ULIDs in a monotonically increasing sequence.
When generating ULIDs within the same millisecond, the random component is incremented to ensure strict monotonicity. If more than 2^80 ULIDs are generated within the same millisecond, generation will fail.

isUlidValid

Checks if a string is a valid ULID.

getUlidBytes

Returns the byte array representation of a ULID string.

makeUlidFromBytes

Constructs a ULID string from a byte array.

Types

UlidOptions

Options for generating ULIDs.

Comparison: UUID vs ULID

Examples

For new projects, consider using ULIDs for primary keys if you benefit from time-based sorting. For compatibility with existing systems or maximum randomness, use UUID v4.