vael:uuid
RFC 9562 UUID v4 and v7 generators backed by the operating system CSPRNG.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Both generators are synchronous, take no arguments, and return canonical
36-character lowercase hyphenated UUID strings.
import ... from "vael:uuid"
vaeljs-core; vael-uuid (default) in vaeljs-lite-coreExample
Section titled “Example”import { v4, v7 } from "vael:uuid";
console.log("v4:", v4());console.log("v7:", v7());Functions
Section titled “Functions”export function v4(): string;
Generate a canonical lowercase RFC 9562 version 4 (random) UUID string (36 characters) using the OS CSPRNG.
string — Canonical 36-character lowercase RFC 9562 UUIDv4 string.TypeError— when any argument is supplied.Error— withcode = "VAEL_UUID_RANDOM"when the OS CSPRNG fails.
import { v4 } from "vael:uuid";
const id = v4();console.log(id.length); // 36export function v7(): string;
Generate a canonical lowercase RFC 9562 version 7 (Unix-time-ordered + random) UUID string (36 characters) using the OS CSPRNG.
Embeds the current Unix millisecond timestamp in the high 48 bits; does not
promise strict monotonicity within a millisecond or across clock steps.
Refuses timestamps before the Unix epoch or >= 2^48 ms with VAEL_UUID_CLOCK.
string — Canonical 36-character lowercase RFC 9562 UUIDv7 string.TypeError— when any argument is supplied.Error— withcode"VAEL_UUID_CLOCK"or"VAEL_UUID_RANDOM".
import { v7 } from "vael:uuid";
const id = v7();console.log(id.length); // 36Type Aliases
Section titled “Type Aliases”UuidErrorCode
Section titled “UuidErrorCode”export type UuidErrorCode = "VAEL_UUID_RANDOM" | "VAEL_UUID_CLOCK" | "VAEL_UUID_INTERNAL";
Error codes thrown by vael:uuid generators on Error.code.
