ulid-workers
Version:
ULID generator for Cloudflare workers
33 lines (32 loc) • 1.38 kB
TypeScript
export declare type ULID = string;
export declare type ULIDFactoryArgs = {
monotonic?: boolean;
};
export declare type ULIDFactory = (timestamp?: number) => ULID;
declare function webCryptoPRNG(): number;
declare function encodeRandom(len: number): string;
declare function validateTimestamp(timestamp: number): void;
export declare function encodeTime(timestamp: number): string;
declare function incrementBase32(str: string): string;
declare function randomChar(): string;
declare function replaceCharAt(str: string, index: number, char: string): string;
/**
* Decode the time component of a ULID to a number representing the UNIX epoch timestamp in milliseconds.
* @param {string} id - A ULID string.
* @returns {number} The UNIX epoch timestamp in milliseconds.
*/
export declare function decodeTime(id: string): number;
/**
* @param {ULIDFactoryArgs} args - An Object representing valid arguments for the ULID factory.
* @returns {ULIDFactory} A function that generates ULIDs.
*/
export declare const ulidFactory: (args?: ULIDFactoryArgs) => ULIDFactory;
export declare const exportedForTesting: {
encodeRandom: typeof encodeRandom;
incrementBase32: typeof incrementBase32;
randomChar: typeof randomChar;
replaceCharAt: typeof replaceCharAt;
validateTimestamp: typeof validateTimestamp;
webCryptoPRNG: typeof webCryptoPRNG;
};
export {};