ULID

One common need for distributed systems are identifiers. ULIDs are a universally unique lexicographically sortable identifier with some nice properties. They are 128-bit values, encoded as 26 character strings which also encode the timestamp. They sort by creation time, which makes them good database keys.

Edit on GitHub

The standard library contains a function for generating ULIDs.

import { ulid } from "jsr:@ende/ulid@^2026.10.15";

To generate a ULID, simply call the function.

console.log(ulid());
console.log(ulid());
console.log(ulid());

ULIDs can also be generated from a timestamp. This is useful for migrating from another system.

const timestamp = Date.now();
console.log(ulid(timestamp));
console.log(ulid(timestamp));
console.log(ulid(timestamp));

Given a ULID, you can get the timestamp back out

import { decodeTime } from "jsr:@ende/ulid@^2026.10.15";
const myULID = ulid();
console.log(decodeTime(myULID));

Optionally, if you’re not on a distributed system and want monotonic ULIDs, you can use the monotonic ULID generator instead.

import { monotonicUlid } from "jsr:@ende/ulid@^2026.10.15";
console.log(monotonicUlid(150000)); // 000XAL6S41ACTAV9WEVGEMMVR8
console.log(monotonicUlid(150000)); // 000XAL6S41ACTAV9WEVGEMMVR9
console.log(monotonicUlid(150000)); // 000XAL6S41ACTAV9WEVGEMMVRA

Run this example locally using the Ende CLI:

ende run https://docs.ende.sh/examples/scripts/ulid.ts

Additional resources