Skip to content

uuid7

Generates a UUID v7 string (RFC 9562). UUID v7 embeds a Unix timestamp in milliseconds, making it chronologically sortable while retaining randomness.

Available since v2.0.0

import { uuid7 } from '@helpers4/id';
uuid7(): string

string — A UUID v7 string in the format xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx

Produces a RFC 9562 UUID v7 string with an embedded millisecond timestamp.

uuid7()
// => "019077e0-5c70-7b3a-8a1f-3e4d5b6c7d8e"

UUID v7 values generated later are lexicographically greater, making them ideal for database primary keys.

const id1 = uuid7();
// ... later ...
const id2 = uuid7();
id1 < id2 // => true

No two calls produce the same value.

uuid7() !== uuid7() // => true

View source on GitHub