uuid
PoolZero-dependency UUID library - Modern, tree-shakeable alternative to uuid package
dist
Functions
function uuidv4(): string
Generate UUID v4 (random) Uses native crypto.randomUUID() for maximum performance and security. Generates a version 4 UUID with 122 bits of randomness. Requires Node.js 18+ or modern browsers with Web Crypto API support.
function uuidv7(options?: V7Options): string
Generate UUID v7 (time-ordered) Generates a version 7 UUID with: - 48-bit Unix timestamp (millisecond precision) - 74 bits of randomness (with monotonic counter for same-ms UUIDs) UUIDs are lexicographically sortable, making them ideal for: - Database primary keys (better B-tree index performance) - Distributed systems requiring time-ordered IDs - Event sourcing and audit logs Guarantees monotonic ordering within the same millisecond through an internal counter that increments for each UUID generated.
| Parameter | Type | Description |
|---|---|---|
optionsoptional | V7Options | - Optional generation options (mainly for testing) |
function uuidv5(name: string, namespace: string | Uint8Array): Promise<string>
Generate UUID v5 (SHA-1 namespace) Generates a version 5 UUID using SHA-1 hashing of a namespace UUID and a name. Same namespace + name combination will always produce the same UUID (deterministic). This is useful for: - Content-addressed identifiers - Idempotent operations - Reproducible UUIDs from known inputs **Note**: This is an async function because it uses Web Crypto API's SHA-1. For synchronous generation in Node.js, use .
| Parameter | Type | Description |
|---|---|---|
name | string | - Name string to hash |
namespace | string | Uint8Array | - Namespace UUID (string or bytes). Use predefined constants like NAMESPACE_DNS, NAMESPACE_URL |
function uuidv5Sync(name: string, namespace: string | Uint8Array): string
Generate UUID v5 synchronously (Node.js only) Synchronous version of using Node.js crypto module. Only works in Node.js environment, not in browsers.
| Parameter | Type | Description |
|---|---|---|
name | string | - Name string to hash |
namespace | string | Uint8Array | - Namespace UUID (string or bytes) |
function validate(uuid: string, version?: UUIDVersion): boolean
Validate UUID format Checks if a string is a valid UUID according to RFC 9562. Optionally validates against a specific UUID version.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID string to validate |
versionoptional | UUIDVersion | - Optional: specific version to validate (1-8) |
function version(uuid: string): UUIDVersion | null
Detect UUID version Extracts the version number from a UUID string. Returns the version (1-8) if valid, or null if invalid.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID string |
function parse(uuid: string): Uint8Array
Parse UUID string to Uint8Array (16 bytes) Converts a standard UUID string format to its binary representation as a 16-byte Uint8Array.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID string (with or without hyphens) |
function stringify(bytes: Uint8Array): string
Convert Uint8Array to UUID string Converts a 16-byte Uint8Array to a standard UUID string format (lowercase, hyphenated: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | - 16-byte Uint8Array representing the UUID |
function extractTimestamp(uuid: string): Date | null
Extract timestamp from UUID v7 as Date Extracts the 48-bit Unix timestamp (in milliseconds) from a UUID v7 and returns it as a JavaScript Date object. UUID v7 stores a millisecond-precision timestamp in the first 48 bits, making it possible to extract the exact time the UUID was generated.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID v7 string |
function extractTimestampMs(uuid: string): number | null
Extract timestamp from UUID v7 as milliseconds Extracts the 48-bit Unix timestamp (in milliseconds) from a UUID v7 and returns it as a number.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID v7 string |
Variables
unknownNIL UUID (all zeros) Special UUID representing "null" or "no value" Defined in RFC 9562
unknownMAX UUID (all Fs) Special UUID representing the maximum possible value Defined in RFC 9562
unknownDNS namespace UUID for UUID v5 Use this namespace for generating UUIDs from DNS domain names Defined in RFC 9562 Appendix A
unknownURL namespace UUID for UUID v5 Use this namespace for generating UUIDs from URLs Defined in RFC 9562 Appendix A
unknownISO OID namespace UUID for UUID v5 Use this namespace for generating UUIDs from ISO OIDs Defined in RFC 9562 Appendix A
unknownX.500 DN namespace UUID for UUID v5 Use this namespace for generating UUIDs from X.500 Distinguished Names Defined in RFC 9562 Appendix A
dist
Functions
function uuidv4(): string
Generate UUID v4 (random) Uses native crypto.randomUUID() for maximum performance and security. Generates a version 4 UUID with 122 bits of randomness. Requires Node.js 18+ or modern browsers with Web Crypto API support.
function uuidv7(options?: V7Options): string
Generate UUID v7 (time-ordered) Generates a version 7 UUID with: - 48-bit Unix timestamp (millisecond precision) - 74 bits of randomness (with monotonic counter for same-ms UUIDs) UUIDs are lexicographically sortable, making them ideal for: - Database primary keys (better B-tree index performance) - Distributed systems requiring time-ordered IDs - Event sourcing and audit logs Guarantees monotonic ordering within the same millisecond through an internal counter that increments for each UUID generated.
| Parameter | Type | Description |
|---|---|---|
optionsoptional | V7Options | - Optional generation options (mainly for testing) |
function uuidv5(name: string, namespace: string | Uint8Array): Promise<string>
Generate UUID v5 (SHA-1 namespace) Generates a version 5 UUID using SHA-1 hashing of a namespace UUID and a name. Same namespace + name combination will always produce the same UUID (deterministic). This is useful for: - Content-addressed identifiers - Idempotent operations - Reproducible UUIDs from known inputs **Note**: This is an async function because it uses Web Crypto API's SHA-1. For synchronous generation in Node.js, use .
| Parameter | Type | Description |
|---|---|---|
name | string | - Name string to hash |
namespace | string | Uint8Array | - Namespace UUID (string or bytes). Use predefined constants like NAMESPACE_DNS, NAMESPACE_URL |
function uuidv5Sync(name: string, namespace: string | Uint8Array): string
Generate UUID v5 synchronously (Node.js only) Synchronous version of using Node.js crypto module. Only works in Node.js environment, not in browsers.
| Parameter | Type | Description |
|---|---|---|
name | string | - Name string to hash |
namespace | string | Uint8Array | - Namespace UUID (string or bytes) |
function validate(uuid: string, version?: UUIDVersion): boolean
Validate UUID format Checks if a string is a valid UUID according to RFC 9562. Optionally validates against a specific UUID version.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID string to validate |
versionoptional | UUIDVersion | - Optional: specific version to validate (1-8) |
function version(uuid: string): UUIDVersion | null
Detect UUID version Extracts the version number from a UUID string. Returns the version (1-8) if valid, or null if invalid.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID string |
function parse(uuid: string): Uint8Array
Parse UUID string to Uint8Array (16 bytes) Converts a standard UUID string format to its binary representation as a 16-byte Uint8Array.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID string (with or without hyphens) |
function stringify(bytes: Uint8Array): string
Convert Uint8Array to UUID string Converts a 16-byte Uint8Array to a standard UUID string format (lowercase, hyphenated: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | - 16-byte Uint8Array representing the UUID |
function extractTimestamp(uuid: string): Date | null
Extract timestamp from UUID v7 as Date Extracts the 48-bit Unix timestamp (in milliseconds) from a UUID v7 and returns it as a JavaScript Date object. UUID v7 stores a millisecond-precision timestamp in the first 48 bits, making it possible to extract the exact time the UUID was generated.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID v7 string |
function extractTimestampMs(uuid: string): number | null
Extract timestamp from UUID v7 as milliseconds Extracts the 48-bit Unix timestamp (in milliseconds) from a UUID v7 and returns it as a number.
| Parameter | Type | Description |
|---|---|---|
uuid | string | - UUID v7 string |
Variables
unknownNIL UUID (all zeros) Special UUID representing "null" or "no value" Defined in RFC 9562
unknownMAX UUID (all Fs) Special UUID representing the maximum possible value Defined in RFC 9562
unknownDNS namespace UUID for UUID v5 Use this namespace for generating UUIDs from DNS domain names Defined in RFC 9562 Appendix A
unknownURL namespace UUID for UUID v5 Use this namespace for generating UUIDs from URLs Defined in RFC 9562 Appendix A
unknownISO OID namespace UUID for UUID v5 Use this namespace for generating UUIDs from ISO OIDs Defined in RFC 9562 Appendix A
unknownX.500 DN namespace UUID for UUID v5 Use this namespace for generating UUIDs from X.500 Distinguished Names Defined in RFC 9562 Appendix A
Taxes calculated at checkout based on your location.