Neo Zero

uuid

Pool

Zero-dependency UUID library - Modern, tree-shakeable alternative to uuid package

$ lpm install @lpm.dev/neo.uuid
32 exportsTypeScript

dist

Functions

uuidv4
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.

uuidv7
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.

ParameterTypeDescription
optionsoptional
V7Options- Optional generation options (mainly for testing)
uuidv5
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 .

ParameterTypeDescription
name
string- Name string to hash
namespace
string | Uint8Array- Namespace UUID (string or bytes). Use predefined constants like NAMESPACE_DNS, NAMESPACE_URL
uuidv5Sync
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.

ParameterTypeDescription
name
string- Name string to hash
namespace
string | Uint8Array- Namespace UUID (string or bytes)
validate
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.

ParameterTypeDescription
uuid
string- UUID string to validate
versionoptional
UUIDVersion- Optional: specific version to validate (1-8)
version
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.

ParameterTypeDescription
uuid
string- UUID string
parse
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.

ParameterTypeDescription
uuid
string- UUID string (with or without hyphens)
stringify
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)

ParameterTypeDescription
bytes
Uint8Array- 16-byte Uint8Array representing the UUID
extractTimestamp
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.

ParameterTypeDescription
uuid
string- UUID v7 string
extractTimestampMs
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.

ParameterTypeDescription
uuid
string- UUID v7 string

Variables

NILunknown

NIL UUID (all zeros) Special UUID representing "null" or "no value" Defined in RFC 9562

MAXunknown

MAX UUID (all Fs) Special UUID representing the maximum possible value Defined in RFC 9562

NAMESPACE_DNSunknown

DNS namespace UUID for UUID v5 Use this namespace for generating UUIDs from DNS domain names Defined in RFC 9562 Appendix A

NAMESPACE_URLunknown

URL namespace UUID for UUID v5 Use this namespace for generating UUIDs from URLs Defined in RFC 9562 Appendix A

NAMESPACE_OIDunknown

ISO OID namespace UUID for UUID v5 Use this namespace for generating UUIDs from ISO OIDs Defined in RFC 9562 Appendix A

NAMESPACE_X500unknown

X.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

uuidv4
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.

uuidv7
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.

ParameterTypeDescription
optionsoptional
V7Options- Optional generation options (mainly for testing)
uuidv5
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 .

ParameterTypeDescription
name
string- Name string to hash
namespace
string | Uint8Array- Namespace UUID (string or bytes). Use predefined constants like NAMESPACE_DNS, NAMESPACE_URL
uuidv5Sync
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.

ParameterTypeDescription
name
string- Name string to hash
namespace
string | Uint8Array- Namespace UUID (string or bytes)
validate
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.

ParameterTypeDescription
uuid
string- UUID string to validate
versionoptional
UUIDVersion- Optional: specific version to validate (1-8)
version
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.

ParameterTypeDescription
uuid
string- UUID string
parse
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.

ParameterTypeDescription
uuid
string- UUID string (with or without hyphens)
stringify
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)

ParameterTypeDescription
bytes
Uint8Array- 16-byte Uint8Array representing the UUID
extractTimestamp
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.

ParameterTypeDescription
uuid
string- UUID v7 string
extractTimestampMs
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.

ParameterTypeDescription
uuid
string- UUID v7 string

Variables

NILunknown

NIL UUID (all zeros) Special UUID representing "null" or "no value" Defined in RFC 9562

MAXunknown

MAX UUID (all Fs) Special UUID representing the maximum possible value Defined in RFC 9562

NAMESPACE_DNSunknown

DNS namespace UUID for UUID v5 Use this namespace for generating UUIDs from DNS domain names Defined in RFC 9562 Appendix A

NAMESPACE_URLunknown

URL namespace UUID for UUID v5 Use this namespace for generating UUIDs from URLs Defined in RFC 9562 Appendix A

NAMESPACE_OIDunknown

ISO OID namespace UUID for UUID v5 Use this namespace for generating UUIDs from ISO OIDs Defined in RFC 9562 Appendix A

NAMESPACE_X500unknown

X.500 DN namespace UUID for UUID v5 Use this namespace for generating UUIDs from X.500 Distinguished Names Defined in RFC 9562 Appendix A

Unlimited AccessInstall as many Pool packages as you need.
Fund Real WorkEvery install you run sends revenue directly to the developer who built it.

Taxes calculated at checkout based on your location.

Weekly Installs
3
Version
1.0.0
Published
LicenseMIT
Size119.18 KB
Files13
Node version>= 18
TypeScriptYes