snowflakify
Version:
The most complete Snowflake ID generator in TypeScript
32 lines (31 loc) • 1.04 kB
TypeScript
import FragmentBase from '../FragmentBase.js';
import { DestructuredFragment } from '../@types/index.js';
/**
* NetworkFragment class for network IDs.
* @public
*/
export default class NetworkFragment extends FragmentBase {
readonly networkAddress: 'ipv4' | 'mac';
/**
* @param bits - The number of bits for the fragment.
* @param networkAddress - The type of network address to use, `"ipv4"` or `"mac"`.
*
* Defaults to `"ipv4"` if omitted.
*
* @throws `[NETWORK_ADDRESS_INVALID]` If networkAddress is not "ipv4" or "mac".
*/
constructor(bits: number, networkAddress?: 'ipv4' | 'mac');
getValue(): bigint;
destructure(snowflake: number | bigint | string): DestructuredFragment;
updateId(): void;
/**
* Returns the network ID.
*
* @remarks
* The value is masked by the maxValue to fit in the fragment's bits.
*
* @returns The network ID of the machine based on a non internal network address.
* @internal
*/
private getNetworkId;
}