Class UUID

Represents a UUID as a 16-byte byte array.

Properties

bytes: Readonly<Uint8Array>

The 16-byte byte array representation.

Methods

  • Returns a negative integer, zero, or positive integer if this is less than, equal to, or greater than other, respectively.

    Parameters

    Returns number

  • Returns true if this is equivalent to other.

    Parameters

    Returns boolean

  • Reports the variant field value of the UUID or, if appropriate, "NIL" or "MAX".

    For convenience, this method reports "NIL" or "MAX" if this represents the Nil or Max UUID, although the Nil and Max UUIDs are technically subsumed under the variants 0b0 and 0b111, respectively.

    Returns
        | "VAR_0"
        | "VAR_10"
        | "VAR_110"
        | "VAR_RESERVED"
        | "NIL"
        | "MAX"

  • Returns the version field value of the UUID or undefined if the UUID does not have the variant field value of 0b10.

    Returns undefined | number

  • Returns string

    The 32-digit hexadecimal representation without hyphens (0189dcd553117d408db09496a2eef37b).

  • Returns string

    The 8-4-4-4-12 canonical hexadecimal string representation.

  • Returns string

    The 8-4-4-4-12 canonical hexadecimal string representation (0189dcd5-5311-7d40-8db0-9496a2eef37b).

  • Builds a byte array from UUIDv7 field values.

    Parameters

    • unixTsMs: number

      A 48-bit unix_ts_ms field value.

    • randA: number

      A 12-bit rand_a field value.

    • randBHi: number

      The higher 30 bits of 62-bit rand_b field value.

    • randBLo: number

      The lower 32 bits of 62-bit rand_b field value.

    Returns UUID

    RangeError if any field value is out of the specified range.

  • Creates an object from the internal representation, a 16-byte byte array containing the binary UUID representation in the big-endian byte order.

    This method does NOT shallow-copy the argument, and thus the created object holds the reference to the underlying buffer.

    Parameters

    • bytes: Readonly<Uint8Array>

    Returns UUID

    TypeError if the length of the argument is not 16.

  • Builds a byte array from a string representation.

    This method accepts the following formats:

    • 32-digit hexadecimal format without hyphens: 0189dcd553117d408db09496a2eef37b
    • 8-4-4-4-12 hyphenated format: 0189dcd5-5311-7d40-8db0-9496a2eef37b
    • Hyphenated format with surrounding braces: {0189dcd5-5311-7d40-8db0-9496a2eef37b}
    • RFC 9562 URN format: urn:uuid:0189dcd5-5311-7d40-8db0-9496a2eef37b

    Leading and trailing whitespaces represents an error.

    Parameters

    • uuid: string

    Returns UUID

    SyntaxError if the argument could not parse as a valid UUID string.