From 2c9fe842340b0cc0ebd0f79a7c190cd575cd2d10 Mon Sep 17 00:00:00 2001 From: Luc Date: Sat, 1 Jan 2022 20:01:09 +0100 Subject: [PATCH] Adapt sunflake generation to create builder-function (#2) --- src/index.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 093c035..ba7aa52 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,18 +9,8 @@ export type SunflakeConfig = { time?: number; }; -export const generateSunflake = async (config: SunflakeConfig) => { - let { machineID, epoch, time } = Object.assign< - SunflakeConfig, - Partial - >( - { - epoch: 0, - machineID: 0, - time: 1, - }, - config - ) as Required; +export const generateSunflake = (config: SunflakeConfig) => async () => { + let { machineID, epoch, time = Date.now() } = config; lastTime = time; machineID = machineID % 1023;