Skip to main content

UUID

UUID

Universally Unique Identifier (UUID), a 128 bit label used to uniquely identify resources. The default is Nil UUID, where all bits are set to 0, see UUID.nil. Also known as GUID ( Globally Unique IDentifier).

Kind: global class
See: IETF RFC 4122 - https://datatracker.ietf.org/doc/html/rfc4122
Author: Alex Goldring
Copyright: Company Named Limited (c) 2025

new exports.UUID()

Example

class Student{
id: UUID
name: string
age: number
}

Example

const id_a = UUID.v1();
const id_b = UUID.v1();

id_a.equals(id_b); // false

uuiD.data

Kind: instance property of UUID

ParamType
bytesArray.<number> | Uint8Array | ArrayLike.<number>

uuiD.data ⇒ Uint8Array

Kind: instance property of UUID

uuiD.version ⇒ number

The version number is in the most significant 4 bits of the timestamp (bits 4 through 7 of the time_hi_and_version field).

Kind: instance property of UUID
See: https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.3
Example

UUID.v1().version === 1
UUID.v4().version === 4

uuiD.toJSON

Kind: instance property of UUID
Read only: true

uuiD.fromJSON

Kind: instance property of UUID
Read only: true

uuiD.isUUID : boolean

Kind: instance property of UUID
Read only: true

uuiD.nil() ⇒ void

The nil UUID is special form of UUID that is specified to have all 128 bits set to zero. Clears all bits of this UUID.

Kind: instance method of UUID

uuiD.v1() ⇒ void

Generate Variant 1 UUID

Kind: instance method of UUID

uuiD.v4() ⇒ void

Generate Variant 4 UUID (fully random)

Kind: instance method of UUID

uuiD.toString() ⇒ string

Standard UUID string in from: AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE Result is compatible with the parse method.

Kind: instance method of UUID
Example

a88bb73a-c89f-11ed-afa1-0242ac120002

uuiD.copy(other)

Sets this UUID to hold the same value as the other

Kind: instance method of UUID

ParamType
otherUUID

uuiD.clone() ⇒ UUID

Kind: instance method of UUID

uuiD.equals(other) ⇒ boolean

Kind: instance method of UUID

ParamType
otherUUID

uuiD.hash() ⇒ number

Compute hash sum

Kind: instance method of UUID
Returns: number - 32bit integer value

UUID.typeName : string

Kind: static property of UUID
Read only: true

UUID.v1() ⇒ UUID

Kind: static method of UUID

UUID.v4() ⇒ UUID

Variant 4 UUID generator (fully random)

Kind: static method of UUID

UUID.string() ⇒ string

Shortcut to generate string-form ID Uses v4(random) UUID

Kind: static method of UUID

UUID.parse(string) ⇒ UUID

Kind: static method of UUID

ParamType
stringstring