A modern implementation Snowflake on TypeScript
npm install snowyflakeSnowyflake - A modern implementation Snowflake on TypeScript
| 📖 Documentation |
|---------------------------|
> TypeScript config required "target": "ES2019" or higher
yarn add snowyflake
`$3
`
npm i snowyflake
`Example usage
`js
import { Snowyflake, Epoch } from 'snowyflake';const snowyflake = new Snowyflake({
workerId: 1n,
epoch: Epoch.Twitter // BigInt timestamp
});
const snowflake = snowyflake.nextId();
console.log(snowflake); // => 1075766315999952896n
const deconstructSnowflake = snowyflake.deconstruct(snowflake);
console.log(deconstructSnowflake); // =>
// { timestamp: 1545317651163n,
// workerId: 1n,
// processId: 0n,
// sequence: 0n }
``