Skip to content

Commit

Permalink
Adapt sunflake generation to create builder-function (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans authored Jan 1, 2022
1 parent a14e899 commit 2c9fe84
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ export type SunflakeConfig = {
time?: number;
};

export const generateSunflake = async (config: SunflakeConfig) => {
let { machineID, epoch, time } = Object.assign<
SunflakeConfig,
Partial<SunflakeConfig>
>(
{
epoch: 0,
machineID: 0,
time: 1,
},
config
) as Required<SunflakeConfig>;
export const generateSunflake = (config: SunflakeConfig) => async () => {
let { machineID, epoch, time = Date.now() } = config;

lastTime = time;
machineID = machineID % 1023;
Expand Down

0 comments on commit 2c9fe84

Please # to comment.