UNPKG

snowflakify

Version:

The most complete Snowflake ID generator in TypeScript

32 lines (31 loc) 978 B
import FragmentBase from '../FragmentBase.js'; import { DestructuredFragment } from '../@types/index.js'; /** * WorkerFragment class for worker IDs. * @public */ export default class WorkerFragment extends FragmentBase { /** * @param bits - The number of bits for the fragment. * @param value - A persistent ID value to use for the fragment. * * Defaults to the current worker ID if omitted. * * @throws `[VALUE_INVALID_TYPE]` If value is not a number. * @throws `[VALUE_INVALID_RANGE]` If value is not within 0 and 2 ** bits - 1 */ constructor(bits: number, value?: number); getValue(): bigint; destructure(snowflake: number | bigint | string): DestructuredFragment; updateId(): void; /** * Returns the worker's ID. * * @remarks * The value is masked by the maxValue to fit in the fragment's bits. * * @returns The worker's ID. * @internal */ private getWorkerId; }