generates unique 64-bit snowflake IDs inspired by Twitter and Discord IDs
npm install @whackdevelopment/snowflakeid---
> npm install @whackdevelopment/snowflakeid
#### NPMJS @whackdevelopment/snowflakeid
---
---
#### Common NodeJS
``js`
const { Snowflake, SnowflakeGenerator } = require('@whackdevelopment/snowflakeid'); / nodejs only /
#### NodeJS ES Module
`js`
import { Snowflake, SnowflakeGenerator } from '@whackdevelopment/snowflakeid';
---
`js`
const flakeGenerator = new SnowflakeGenerator({
machineId: 1, // optional, define machine id (defaults to 1)
timeOffset: 0 // optional, define a offset time (defaults to 0)
});
#### Options
machineId: (Defaults to 1) A machine id or any random id. If you are generating id in distributed system, its highly advised to provide a proper machineId which is unique to different machines.
timeOffset: (Defaults to 0) Time offset will be subtracted from current time to get the first 42 bit of id. This help in generating smaller ids. ( not recommended )
---
`js`
const id1 = flakeGenerator.generate(); // returns something like 112867124767768576
const id2 = flakeGenerator.generate(); // returns something like 112867124784545792
---
`js``
const id1Clone = new Snowflake(id1.toString()); // or
const id2Clone = new Snowflake(id2);
---