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 play very nicely with Deno KV.
import { ulid } from "jsr:@std/ulid@1";console.log(ulid());
console.log(ulid());
console.log(ulid());const timestamp = Date.now();
console.log(ulid(timestamp));
console.log(ulid(timestamp));
console.log(ulid(timestamp));import { decodeTime } from "jsr:@std/ulid@1";
const myULID = ulid();
console.log(decodeTime(myULID));import { monotonicUlid } from "jsr:@std/ulid@1";
console.log(monotonicUlid(150000)); // 000XAL6S41ACTAV9WEVGEMMVR8
console.log(monotonicUlid(150000)); // 000XAL6S41ACTAV9WEVGEMMVR9
console.log(monotonicUlid(150000)); // 000XAL6S41ACTAV9WEVGEMMVRARun this example locally using the Deno CLI:
deno run https://docs.deno.com/examples/scripts/ulid.ts