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
npm
npm install ulidMethods
No methods match this filter.
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) — “
ulidautomatically detects a suitable (cryptographically-secure) PRNG. In the browser it will usecrypto.getRandomValuesand on NodeJS it will usecrypto.randomBytes.” (source: https://raw.githubusercontent.com/ulid/javascript/master/README.md, fetched 2026-11-08T09:53:13.312Z) - 默认不使用不安全的 Math.random,需手动覆盖 PRNG 才会启用 — “By default,
ulidwill not useMath.randomto 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.
ulid→ signature from https://unpkg.com/[email protected]/dist/ulid.d.ts; official text: “export declare function ulid(seedTime?: number, prng?: PRNG): ULID;”ulid.decodeTime→ signature from https://unpkg.com/[email protected]/dist/ulid.d.ts; official text: “export declare function decodeTime(id: ULID): number;”ulid.monotonicFactory→ signature from https://unpkg.com/[email protected]/dist/ulid.d.ts; official text: “export declare function monotonicFactory(prng?: PRNG): ULIDFactory;”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.