A minimal utility for converting between UUID (Universally Unique IDentifier) and ULID (Universally Unique Lexicographically Sortable Identifier) in their string and binary (Uint8Array) forms.
parseUuid(string)
: Convert UUID string toUint8Array
formatUuid(Uint8Array)
: ConvertUint8Array
to UUID stringparseUlid(string)
: Convert ULID string toUint8Array
formatUlid(Uint8Array)
: ConvertUint8Array
to ULID string
import {
formatUlid,
formatUuid,
parseUlid,
parseUuid,
} from "jsr:@core/uxidutil";
const uuid = "123e4567-e89b-12d3-a456-426614174000";
const ulid = "01HZYHQ6X4V9E9ZEM8Y6MVPMX3";
// UUID to bytes and back
const uuidBytes = parseUuid(uuid);
const uuidAgain = formatUuid(uuidBytes);
// ULID to bytes and back
const ulidBytes = parseUlid(ulid);
const ulidAgain = formatUlid(ulidBytes);
// Interchangeable via Uint8Array
const fromUuidToUlid = formatUlid(parseUuid(uuid));
const fromUlidToUuid = formatUuid(parseUlid(ulid));
Parses a standard UUID string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) into a 16-byte array.
Formats a 16-byte array into a UUID string.
Parses a 26-character ULID string into a 16-byte array. Strictly validates Crockford Base32 (excluding I, L, O, U).
Formats a 16-byte array into a 26-character ULID string.
The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.