API Reference

ULID

Generates ULIDs: lexicographically sortable, collision-resistant identifiers that can be monotonic.

Official Documentation ↗
CompatibilityThis documentation covers version v3.0.2. Check the official docs for the latest API surface.

Installation

npmnpm install ulid

Methods

ULID encodes a millisecond timestamp plus randomness into a 26-character Crockford Base32 string.

Key Features

  • Lexicographically sortable by creation time
  • Monotonic factory for same-millisecond order
  • Crockford Base32, URL safe

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Security

Official security statements captured from the package documentation:

  • 默认自动选择密码学安全 PRNG(浏览器 crypto.getRandomValues / Node crypto.randomBytes) — “ulid automatically detects a suitable (cryptographically-secure) PRNG. In the browser it will use crypto.getRandomValues and on NodeJS it will use crypto.randomBytes.” (source: https://raw.githubusercontent.com/ulid/javascript/master/README.md, fetched 2026-11-08T09:53:13.312Z)
  • 默认不使用不安全的 Math.random,需手动覆盖 PRNG 才会启用 — “By default, ulid will not use Math.random to generate random values. You can bypass this limitation by overriding the PRNG:” (source: https://raw.githubusercontent.com/ulid/javascript/master/README.md, fetched 2026-11-08T09:53:13.312Z)

API reference evidence

Fetched from official sources on 2026-11-08T09:53:13.312Z via WebFetch https://unpkg.com/[email protected]/dist/ulid.d.ts.

FAQ

How is ULID different from UUID?
ULIDs are sortable by time and shorter in text form, while UUIDv4 is purely random. ULIDs also expose their creation timestamp.
Do ULIDs leak creation time?
Yes. The first 10 characters encode the timestamp, so treat that as public information when ids are exposed.
When do I need the monotonic factory?
When you generate many ids within the same millisecond and must preserve strict ordering, such as for pagination cursors.