2.0.1 • Published 2 years ago
fast-snowflake-id v2.0.1
Installation
Using npm:
$ npm install fast-snowflake-idUsing yarn:
$ yarn add fast-snowflake-idFeatures
- Get snowflake id as bigint
- Get snowflake id as buffer
Without any dependencies!
Usage/Examples
setup:
// CommonJS
const SnowflakeId = require('fast-snowflake-id').default;
// ES Module
import SnowflakeId from 'fast-snowflake-id';initialization:
// All properties are optional
const snowflakeId = new SnowflakeId({
epoch: 1288834974657 /* Twitter's snowflake id epoch */,
instanceId: SnowflakeId.getInstanceId(31, 31) /* Getting instanceId from datacenterId and workerId */,
overflowHandler: function () {
console.error('overflow!!!!');
return;
}
});printing snowflake id as bigint:
console.log(snowflakeId.getId());printing snowflake id as buffer:
console.log(snowflakeId.getBufferId());Contribution
Contribution, issues and feature requests are welcome!Feel free to check issues page.