@ende/ulid
ende add jsr:@ende/ulidVersion 2026.10.15 on JSR.
Utilities for generating and working with Universally Unique Lexicographically Sortable Identifiers (ULIDs).
To generate a ULID use the ulid function. This will generate a
ULID based on the current time.
import { ulid } from "@ende/ulid";
ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
ulid does not guarantee that the ULIDs will be strictly
increasing for the same current time. If you need to guarantee that the ULIDs
will be strictly increasing, even for the same current time, use the
monotonicUlid function.
import { monotonicUlid } from "@ende/ulid";
monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
Because each ULID encodes the time it was generated, you can extract the
timestamp from a ULID using the decodeTime function.
import { decodeTime, ulid } from "@ende/ulid";
import { assertEquals } from "@ende/assert";
const timestamp = 150_000;
const ulidString = ulid(timestamp);
assertEquals(decodeTime(ulidString), timestamp);
Modules
Exports
decodeTime— Extracts the number of milliseconds since the Unix epoch that had passed when the ULID was generated. If the ULID is malformed, an error will be thrown.monotonicUlid— Generate a ULID that monotonically increases even for the same millisecond, optionally passing the current time. If the current time is not passed, it will default to `Date.now()`.ulid— Generate a ULID, optionally based on a given timestamp. If the timestamp is not passed, it will default to `Date.now()`.