Return this UUID formatted as a string.
@param style Optional output style. Defaults to "canonical".
@eryx/uuid ModuleUUID generation, parsing, and formatting.
This module implements the RFC 9562 UUID families v1, v3, v4,
v5, v6, v7, and v8, along with parsing, coercion, comparison,
and formatting helpers.
UUIDs may be consumed as canonical strings, raw 16-byte buffer
values, or metatable-backed UUID objects returned by this module.
Parsed and generated UUID objects expose common metadata such as
variant, version, and bytes, with additional version-specific
fields available on timestamped layouts like v1, v6, and v7.
Version overview:
v1 Time-based UUIDs with Gregorian 100ns timestamps, clock sequence, and node ID.v3 Namespace-name UUIDs hashed with MD5.v4 Random UUIDs generated from a cryptographically secure RNG.v5 Namespace-name UUIDs hashed with SHA-1.v6 Reordered time-based UUIDs optimized for bytewise sorting.v7 Unix-millisecond ordered UUIDs intended for new sortable identifiers.v8 Application-defined UUID layouts with normalized version and variant bits.Textual forms:
123e4567-e89b-12d3-a456-426614174000123e4567e89b12d3a456426614174000{123e4567-e89b-12d3-a456-426614174000}urn:uuid:123e4567-e89b-12d3-a456-426614174000local uuid = require("@eryx/uuid")
local id = uuid.v7()
print(id.kind) -- "v7"
print(uuid.format(id)) -- canonical UUID string
local parsed = uuid.parse("01890f3a-b5f7-7c0d-8f50-8f8c2c7adf4d")
print(parsed.kind, parsed.version) -- "v7", 7
Return this UUID formatted as a string.
@param style Optional output style. Defaults to "canonical".
The formatted UUID string.
Return a copy of this UUID's raw 16-byte representation.
A new buffer containing the UUID bytes.
Check whether this UUID equals another UUID-like value.
A UUID object, UUID string, or 16-byte buffer.
true when both values encode the same bytes.
Compare this UUID to another UUID-like value using bytewise ordering.
@param other A UUID object, UUID string, or 16-byte buffer.
-1, 0, or 1 depending on ordering.
Check whether this UUID is the all-zero nil UUID.
true when every byte is zero.
Return the recoverable Unix-millisecond timestamp for timestamped UUIDs.
For v1 and v6, this is derived from the embedded Gregorian 100ns
timestamp. For v7, it is the native Unix-millisecond field. Other
UUID versions return nil.
Unix milliseconds, or nil when not applicable.
Parse a UUID string into a UUID object.
Canonical hyphenated strings are always accepted. Hyphenless, braced,
and URN forms may be enabled through options.
UUID string to parse.
Optional parse flags controlling accepted textual forms.
Parsed UUID object with recovered metadata where available.
Parse a UUID string, returning nil instead of raising on invalid input.
UUID string to parse.
Optional parse flags controlling accepted textual forms.
Parsed UUID object, or nil when parsing fails.
Coerce a UUID-like value into a UUID object.
Existing UUID objects are returned as-is. Strings are parsed, and 16-byte buffers are decoded directly.
UUID object, UUID string, or 16-byte buffer.
Optional parse flags used when value is a string.
Normalized UUID object.
Return whether a UUID-like value can be successfully coerced.
UUID object, UUID string, or 16-byte buffer.
Optional parse flags used when value is a string.
true when coercion succeeds.
Format a UUID-like value into a textual representation.
UUID object, UUID string, or 16-byte buffer.
Optional output style. Defaults to "canonical".
Formatted UUID string.
Return a copy of a UUID-like value as a raw 16-byte buffer.
UUID object, UUID string, or 16-byte buffer.
New buffer containing the UUID bytes.
Check whether two UUID-like values are bytewise equal.
true when both values encode the same UUID.
Compare two UUID-like values using raw byte ordering.
This is useful for sortable UUID families such as v6 and v7, or
when storing UUIDs in ordered indexes.
-1, 0, or 1 depending on ordering.
Generate a version 1 UUID.
When not explicitly supplied, the node and clock sequence are derived
from cryptographically secure random bytes. The nanoseconds field
represents the sub-millisecond portion of the timestamp and must be a
multiple of 100.
Optional generation controls.
Generated version 1 UUID.
Generate a version 3 namespace-name UUID using MD5.
Namespace and name to hash.
Generated version 3 UUID.
Generate a version 4 random UUID.
By default this uses @eryx/crypto/hazmat/random.bytes.
Optional RNG override.
Generated version 4 UUID.
Generate a version 5 namespace-name UUID using SHA-1.
Namespace and name to hash.
Generated version 5 UUID.
Generate a version 6 reordered time-based UUID.
This uses the same Gregorian 100ns timestamp source model as v1, but
reorders the bytes to improve sort locality.
Optional generation controls.
Generated version 6 UUID.
Generate a version 7 Unix-time-ordered UUID.
When sequence is omitted, this module applies monotonic sequencing so
that repeated calls remain bytewise ordered even within the same
millisecond.
Optional generation controls.
Generated version 7 UUID.
Generate a version 8 UUID from caller-supplied bytes.
The provided payload must be exactly 16 bytes long. The version and
variant bits are normalized to match a valid v8 UUID.
Raw payload bytes to wrap as a version 8 UUID.
Generated version 8 UUID.
Gregorian timestamp in 100ns intervals since 1582-10-15.
Convenience timestamp in Unix milliseconds.
14-bit clock sequence.
48-bit node identifier as 6 bytes.
Reordered Gregorian timestamp in 100ns intervals since 1582-10-15.
Convenience timestamp in Unix milliseconds.
14-bit clock sequence.
48-bit node identifier as 6 bytes.
Milliseconds since the Unix epoch.
The 12-bit rand_a field.
The trailing 64-bit payload as 8 bytes, including variant bits.