UNPKG

universal-common

Version:

Library that provides useful missing base class library functionality.

60 lines (59 loc) 2.26 kB
/** * A utility class for generating and manipulating Globally Unique Identifiers (GUIDs). * This implementation creates RFC4122 version 4 compliant UUIDs. * The class stores GUIDs as byte arrays internally for efficient operations. */ export default class Guid { /** * Creates a Guid from a byte array. * @param {Uint8Array} bytes - A 16-byte array. * @returns {Guid} A new Guid instance. */ static fromBytes(bytes: Uint8Array): Guid; /** * Creates a new random GUID instance. * @returns {Guid} A new Guid instance with random values. */ static newGuid(): Guid; /** * Creates a Guid from a string representation. * @param {string} guidString - The string representation of a GUID. * @returns {Guid} A new Guid instance. * @throws {ArgumentError} If the string is not a valid GUID format. */ static parse(guidString: string): Guid; /** * Tries to parse a GUID string without throwing an exception. * @param {string} guidString - The string to parse. * @param {Object} result - An object with a "value" property that will be set to the parsed GUID if successful. * @returns {Guid?} True if parsing was successful, false otherwise. */ static tryParse(guidString: string): Guid | null; /** * Creates a new Guid instance. * @param {Uint8Array|string|null} value - Optional byte array or string to initialize the GUID. */ constructor(value?: Uint8Array | string | null); /** * Checks if this GUID is equal to another GUID. * @param {Guid} other - The GUID to compare with. * @returns {boolean} True if the GUIDs are equal, false otherwise. */ equals(other: Guid): boolean; /** * Checks if this GUID is the empty GUID. * @returns {boolean} True if this is the empty GUID, false otherwise. */ isEmpty(): boolean; /** * Returns the byte array representation of the GUID. * @returns {Uint8Array} The byte array. */ toBytes(): Uint8Array; /** * Returns the GUID as a hyphenated string. * @returns {string} The string representation. */ toString(): string; #private; }