UNPKG

distid

Version:

Distributed ID generator for large-scale systems

24 lines (23 loc) 799 B
import { DistIdConfig, DistIdFormat } from './types'; export declare class DistIdGenerator { private nodeId; private epoch; private counterBits; private counter; private lastTimestamp; private logger; private static usedNodeIds; constructor(config: DistIdConfig); private getTimestamp; private incrementCounter; /** * Generates a distributed ID for large-scale systems. * @param format - The output format of the ID ('number', 'hex', 'base36', 'base62'). * @returns A unique ID in the specified format. * @example * const gen = new DistIdGenerator({ nodeId: 5 }); * console.log(gen.generate('hex')); // e.g., "13a8f5c00050007b" */ generate(format?: DistIdFormat): string | bigint; static resetNodeIds(): void; }