@skorotkiewicz/snowflake-id
Version:
Snowflake ID is a unique identifier commonly used in distributed systems to generate unique IDs with a timestamp component. It is designed to ensure uniqueness, even in distributed and highly concurrent environments.
18 lines (17 loc) • 469 B
TypeScript
export declare class Snowflake {
private machineId;
private sequence;
private lastTimestamp;
private readonly timestampShift;
private readonly machineIdShift;
private readonly sequenceMask;
constructor(machineId: number);
generate(): Promise<string>;
}
interface DecodedSnowflake {
timestamp: string;
machineId: string;
sequence: string;
}
export declare function decodeSnowflake(idStr: string): DecodedSnowflake;
export {};