UNPKG

moonlifedb

Version:

A JSON database with a bunch of tools and typescript support.

50 lines (49 loc) 1.62 kB
export declare class Snowflake { worker: number | bigint; epoch: number | bigint; seq: number | bigint; protected lastTime: number | bigint; /** * Class constructor of an ID generator, based on Twitter Snowflake. * @example const Generator = new Snowflake({ worker: 0, epoch: 1640995200000 }) * @param {(number|undefined)} worker worker ID in number or bigint (Converts to bigint). By default it's 0 * @param {(number|undefined)} epoch epoch ofset where to start generating. Requires milliseconds. */ constructor(settings: { worker: number | bigint | undefined; epoch: number | bigint | undefined; }); /** * Generate a 63 bits long unique ID. * @example const ID = Snowflake.generate(); * @returns {snowflake} snowflake */ generate(): string; /** * Generate a 63 bits long unique ID. * @example const ID = Snowflake.generateRaw(); * @returns {object} snowflake */ generateRaw(): { result: string; raw: { result: string; epoch: number | bigint; epochBinary: string; worker: number | bigint; workerBinary: string; }; }; /** * Decode a 63 bits long unique ID into an object. * @example const ID = Snowflake.decode(snowflake); * * @param snowflake string * @returns {object} snowflake */ decode(snowflake: string): { epoch: number | bigint; worker: number | bigint; sequence: number | bigint; }; }