fast-snowflake-id
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published
banner

Fast snowflake id generator for Node.js

I guess...?

npm version npm type definition license


Installation

Using npm:

$ npm install fast-snowflake-id

Using yarn:

$ yarn add fast-snowflake-id

Features

  • 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.

Package Sidebar

Install

npm i fast-snowflake-id

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

5.54 kB

Total Files

5

Last publish

Collaborators

  • h2owater425