Skip to main content

@std/ulid@1.0.0
Built and signed on GitHub Actions

Generation of Universally Unique Lexicographically Sortable Identifiers (ULIDs)

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
8 months ago (1.0.0)

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 "@std/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 "@std/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 "@std/ulid";
import { assertEquals } from "@std/assert";

const timestamp = 150_000;
const ulidString = ulid(timestamp);

assertEquals(decodeTime(ulidString), timestamp);
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@std/ulid

Import symbol

import * as ulid from "@std/ulid";

---- OR ----

Import directly with a jsr specifier

import * as ulid from "jsr:@std/ulid";

Add Package

npx jsr add @std/ulid

Import symbol

import * as ulid from "@std/ulid";

Add Package

yarn dlx jsr add @std/ulid

Import symbol

import * as ulid from "@std/ulid";

Add Package

pnpm dlx jsr add @std/ulid

Import symbol

import * as ulid from "@std/ulid";

Add Package

bunx jsr add @std/ulid

Import symbol

import * as ulid from "@std/ulid";