Constructor
new Uuid(uuid)
Creates a universally unique identifier (UUID) from an array of fields
Unless you're making advanced use of this library to generate identifiers that deviate RFC 4122, you
probably do not want to instantiate a UUID directly. Use the static methods, instead:
import { Uuid } from '@actually_connor/uuid';
Uuid.uuid4();
Parameters:
Name | Type | Description |
---|---|---|
uuid |
ArrayLike.<number> | The Array-like collection of 16 values (starting from offset) between 0-255 |
Methods
(static) fromBuffer(buffer) → {UuidInterface}
Creates a UUID from a buffer array
Parameters:
Name | Type | Description |
---|---|---|
buffer |
Buffer | A Buffer array |
Returns:
- Type
- UuidInterface
(static) fromBytes(bytes) → {UuidInterface}
Creates a UUID from a byte string
Parameters:
Name | Type | Description |
---|---|---|
bytes |
string | A binary string |
Returns:
A UuidInterface instance created from a binary string representation
- Type
- UuidInterface
(static) fromString(uuid) → {UuidInterface}
Creates a UUID from the string standard representation
Parameters:
Name | Type | Description |
---|---|---|
uuid |
string | A hexadecimal string |
Returns:
A UuidInterface instance created from a hexadecimal string representation
- Type
- UuidInterface
(static) isValid(uuid) → {boolean}
Returns true if the provided string is a valid UUID
Parameters:
Name | Type | Description |
---|---|---|
uuid |
string | A string to validate as a UUID |
Returns:
- Type
- boolean
(static) uuid4() → {UuidInterface}
Returns a version 4 (random) UUID
Returns:
A UuidInterface instance that represents a version 4 UUID
- Type
- UuidInterface
compareTo(other) → {number}
Returns -1, 0, or 1 if the UUID is less than, equal to, or greater than the other UUID
The first of two UUIDs is greater than the second if the most significant field in which the UUIDs differ
is greater for the first UUID.
* Q. What's the value of being able to sort UUIDs?
* A. Use them as keys in a B-Tree or similar mapping.
Parameters:
Name | Type | Description |
---|---|---|
other |
UuidInterface | The UUID to compare |
Returns:
-1, 0, or 1 if the UUID is less than, equal to, or greater than the other
- Type
- number
equals(other) → {boolean}
Returns true if the UUID is equal to the provided object
The result is true if and only if the argument is not null, is a UUID object, has the same variant, and contains
the same value, bit for bit, as the UUID.
Parameters:
Name | Type | Description |
---|---|---|
other |
object | null | An object to test for equality with this UUID |
Returns:
True if the other object is equal to this UUID
- Type
- boolean
getBuffer() → {Buffer}
Returns a buffer array representation of the UUID
Returns:
- Type
- Buffer
getBytes() → {string}
Returns the binary string representation of the UUID
Returns:
- Type
- string
getHex() → {string}
Returns the hexadecimal representation of the UUID
Returns:
- Type
- string
getUuid() → {ArrayLike.<number>}
Returns the Array-like collection of 16 values (starting from offset) between 0-255
Returns:
- Type
- ArrayLike.<number>
toString() → {string}
Returns the string standard representation of the UUID
Returns:
- Type
- string