UNPKG

uuid-class

Version:

A minimal UUID class for JavaScript.

58 lines (57 loc) 2.34 kB
/** * A better UUID class for JavaScript. * * UUID are represented as bytes (`Uint8Array`) and converted to strings on-demand. * * This class implements `toString` and `toJSON` for better language integration, * as well as inspection for node and Deno for a better development experience. * * For the most part, `UUID` can be used where UUID strings are used, * except for equality checks. For those cases, `UUID` provides quick access * to the string representations via the `id` field. */ export declare class UUID extends Uint8Array { /** * Generate a new UUID version 4 (random). * * __Note that `crypto.getRandomValues` needs to be available in the global JS object!__ */ static v4(): UUID; /** * Generated a new UUID version 5 (hashed) * * __Note that `crypto.subtle` needs to be available in the global JS object (Not the case on non-HTTPS sites)!__ * * @param value * @param namespace */ static v5(value: string | BufferSource, namespace: string | UUID): Promise<UUID>; /** * Generate a new UUID version 4 (random). * __Note that `crypto.getRandomValues` needs to be available in the global JS object!__ */ constructor(); /** Creates a new UUID object from the provided string, which must be a valid UUID string. */ constructor(value: string); /** Creates a copy of the provided UUID */ constructor(value: UUID); /** Create a UUID from the provided iterable, where every value will be interpreted as a unsigned 8 bit integer. */ constructor(value: Iterable<number>); /** Create a new UUID from the provided array-like structure. */ constructor(value: ArrayLike<number> | ArrayBufferLike); /** Creates a UUID from the array buffer using 16 bytes started from the provided offset. */ constructor(value: ArrayBufferLike, byteOffset: number); /** * Quick access to the string representation for easier comparison. * @example if (myUUID.id === otherUUID.id) { ... } */ get id(): string; /** * Quick access to the UUID string representation for easier comparison. * @example if (myUUID.uuid === otherUUID.uuid) { ... } */ get uuid(): string; toString(): string; toJSON(): string; static get [Symbol.species](): Uint8ArrayConstructor; }