一个 JavaScript 或 Node 雪花 ID 生成器。 A JavaScript or Node snowflake ID generator.
npm 安装
npm i snowflake-worker -S
yarn 安装
yarn add snowflake-worker -S
pnpm 安装
pnpm i snowflake-worker -S
import SnowflakeWorker from 'snowflake-worker'
const snowflakeWorker = new SnowflakeWorker(1, 1)
const snowflakeId = snowflakeWorker.nextId()
// 或者使用全局唯一雪花对象(全局唯一雪花对象一经创建后不能被修改,重复调用 global 方法不会覆盖)
const snowflakeWorkerGlobal = SnowflakeWorker.global(1, 1)
const snowflakeId2 = snowflakeWorkerGlobal.nextId()