Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ID Generation Functions

Functions for generating various types of unique identifiers.

Summary

FunctionSignatureDescription
nanoidnumber? -> stringGenerate nanoid
ulid-> stringGenerate ULID
ulid_timestampstring -> numberExtract timestamp from ULID

Functions

nanoid

Generate nanoid

Signature: number? -> string

Examples:

# Default 21 chars
nanoid() -> \"V1StGXR8_Z5jdHi6B-myT\"
# Custom length
nanoid(`10`) -> \"IRFa-VaY2b\"

CLI Usage:

echo '{}' | jpx 'nanoid()'

ulid

Generate ULID

Signature: -> string

Examples:

# Generate ULID
ulid() -> \"01ARZ3NDEKTSV4RRFFQ69G5FAV\"
# Always 26 chars
length(ulid()) -> 26

CLI Usage:

echo '{}' | jpx 'ulid()'

ulid_timestamp

Extract timestamp from ULID

Signature: string -> number

Examples:

# Extract timestamp
ulid_timestamp('01ARZ3NDEKTSV4RRFFQ69G5FAV') -> 1469918176385
# Another ULID
ulid_timestamp('01BX5ZZKBKACTAV9WEVGEMMVRY') -> 1484581420610

CLI Usage:

echo '{}' | jpx 'ulid_timestamp(`"01ARZ3NDEKTSV4RRFFQ69G5FAV"`)'