@squidcloud/client
Version:
A typescript implementation of the Squid client
45 lines (44 loc) • 1.74 kB
TypeScript
/**
* Generates a random RFC 4122 version 4 UUID.
* The UUID is generated using a cryptographic pseudorandom number generator.
*/
export declare function generateUUID(): string;
/**
* Generates a UUID-style ID.
* @deprecated Use `generateUUID` instead.
*/
export declare function generateId(): string;
/** Default length if ID produced by `generateShortId`. */
export declare const DEFAULT_SHORT_ID_LENGTH = 18;
/**
* Generates an ID of the given `length` using lowercase latin letters and digits.
* If the 'prefix' provided replaces the first generated characters with the prefix.
* If the 'prefixToAvoid' provided, ensures the generated ID does not start with this prefix.
* When both 'prefix' and 'prefixToAvoid' are provided, 'prefixToAvoid' must be longer than 'prefix'.
*/
export declare function generateShortId(length?: number, prefix?: string, prefixToAvoid?: string): string;
/**
* Generates a set of unique IDs under the same behavior as `generateShortId`.
*
* @param length The length of the ID to be generated. Default is 18.
* @param prefix The prefix of the generated ID. Default is an empty string.
* @param count The number of IDs to be generated.
*/
export declare function generateShortIds({ count, length, prefix }: GenerateShortIdsOptions): string[];
/**
* Options for generating multiple short IDs.
*/
export interface GenerateShortIdsOptions {
/** The number of IDs to generate. */
count: number;
/**
* The length of each generated ID.
* @default DEFAULT_SHORT_ID_LENGTH.
*/
length?: number;
/**
* A string that must be a predefined prefix for each ID. Replaces the first generated characters.
* @default - no prefix.
*/
prefix?: string;
}