UNPKG

@nats-io/nuid

Version:

NUID - A highly performant unique identifier generator.

61 lines (60 loc) 1.32 kB
/** * Nuid is a class that generates unique identifiers. */ export declare class Nuid { /** * @hidden */ buf: Uint8Array; /** * @hidden */ seq: number; /** * @hidden */ inc: number; /** * @hidden */ inited: boolean; constructor(); /** * Initializes a nuid with a crypto random prefix, * and pseudo-random sequence and increment. This function * is only called if any api on a nuid is called. * * @ignore */ private init; /** * Initializes the pseudo random sequence number and the increment range. * @ignore */ private initSeqAndInc; /** * Sets the prefix from crypto random bytes. Converts them to base36. * * @ignore */ private setPre; /** * Fills the sequence part of the nuid as base36 from this.seq. * @ignore */ private fillSeq; /** * Returns the next nuid. */ next(): string; /** * Resets the prefix and counter for the nuid. This is typically * called automatically from within next() if the current sequence * exceeds the resolution of the nuid. */ reset(): void; } /** * A nuid instance you can use by simply calling `next()` on it. */ export declare const nuid: Nuid;