@kwiz/common
Version:
KWIZ common utilities and helpers for M365 platform
120 lines (119 loc) • 3.92 kB
TypeScript
/**
* This class represents a globally unique identifier, as described by
* IETF RFC 4122.
*
* @remarks
* The input string is normalized and validated, which provides
* important guarantees that simplify other code that works with the GUID.
* This class also provides basic support for generating a pseudo-random GUID;
* however, be aware that the uniqueness depends on the browser's `Math.random()`
* function and may be not be suitable for some applications.
*
* See {@link https://www.ietf.org/rfc/rfc4122.txt | RFC4122} for more information.
*
* @public
*/
export declare class Guid {
private _guid;
/**
* Returns a new empty Guid instance.
*
* @returns A new empty Guid object.
*/
static empty: Guid;
private static _guidRegEx;
/**
* Use `Guid.parse()` or `Guid.tryParse()` instead of the constructor.
* @param guid - a normalized, already valid Guid string
*/
constructor(guid: any);
/**
* Returns a new Guid instance with a pseudo-randomly generated GUID, according
* to the version 4 UUID algorithm from RFC 4122.
*
* @returns A new unique Guid object
*/
static newGuid(randomNumberGenerator: any): Guid;
/**
* Parses the input string to construct a new Guid object.
* If the string cannot be parsed, then an error is thrown.
*
* @remarks
* Example syntaxes accepted by this function:
*
* - `"d5369f3bbd7a412a9c0f7f0650bb5489"`
*
* - `"d5369f3b-bd7a-412a-9c0f-7f0650bb5489"`
*
* - `"{d5369f3b-bd7a-412a-9c0f-7f0650bb5489}"`
*
* - `"/Guid(d5369f3b-bd7a-412a-9c0f-7f0650bb5489)/"`
*
* @param guid - The input string.
* @returns A valid Guid object
*/
static parse(guidString: any): Guid;
/**
* Attempts to parse the input string to construct a new Guid object.
* If the string cannot be parsed, then undefined is returned.
*
* @remarks
* Example syntaxes accepted by this function:
*
* - `"d5369f3bbd7a412a9c0f7f0650bb5489"`
*
* - `"d5369f3b-bd7a-412a-9c0f-7f0650bb5489"`
*
* - `"{d5369f3b-bd7a-412a-9c0f-7f0650bb5489}"`
*
* - `"/Guid(d5369f3b-bd7a-412a-9c0f-7f0650bb5489)/"`
*
* @param guid - The input string.
* @returns The Guid object, or undefined if the string could not be parsed.
*/
static tryParse(guid: any): Guid;
/**
* Indicates whether a GUID is valid, i.e. whether it would be successfully
* parsed by `Guid.tryParse()`. This function is cheaper than `Guid.tryParse()`
* because it does not construct a Guid object.
*
* @param guid - The input string.
* @returns true, if the Guid is valid.
*/
static isValid(guid: any): boolean;
/**
* SharePoint can have guids in the form:
* - `Guid(...)`
* - `{...}`
* _normalize transforms guids in this format to the standard
* guid format.
*
* Example: `Guid(d5369f3b-bd7a-412a-9c0f-7f0650bb5489)` becomes `d5369f3b-bd7a-412a-9c0f-7f0650bb5489`
* Example: `{d5369f3b-bd7a-412a-9c0f-7f0650bb5489}` becomes `d5369f3b-bd7a-412a-9c0f-7f0650bb5489`
*
* @param guid - Guid to be normalized, could already be normalized.
* @returns Normalized guid.
*/
private static _normalize;
/**
* Creates a new guid.
*
* @returns A valid guid (according to RFC4122)
*/
private static _generateGuid;
/**
* Compare this instance to another Guid instance
*
* @returns True if this instance and the specified Guid object
* represent the same value.
*/
equals(guid: any): boolean;
/**
* Returns a string representation of the GUID
*
* @returns The GUID value in lowercase hexadecimal without braces.
*
* Example: `'d5369f3b-bd7a-412a-9c0f-7f0650bb5489'`
*/
toString: () => any;
}