ID Generator and deconstructor by TimonDEV.
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
Here's an ID-Generator for you to use as an alternative system to other ID-Generators. It utilizes the power of the Snowflake ID to generate up to 4096 ids per milli-second per worker / process. A Snowflake is a 64-bit integer that consists of four elements:
timestamp | internal workerID | internal processID | increment |
---|---|---|---|
42 bits | 5 bits | 5bits | 12bits |
unique | used for clusters | used for multiprocesses | 0 to 4095 |
To get a started with this project follow these simple steps.
Please use the latest version of npm
or yarn
to install the package.
-
npm
npm install npm@latest -g
-
yarn
npm install --global yarn@latest
-
Install the package using the following command:
npm install @timondev/snowflake-id
-
Try out the following example:
import { SnowflakeID } from '@timondev/snowflake-id'; let id = SnowflakeID.generate(); console.log(`Snowflake generated the following id ${id}`);
-
Or use it to deconstruct snowflakes:
import { SnowflakeID } from '@timondev/snowflake-id'; let id = '86913608335773696'; let snowflake = new SnowflakeID(id); console.log(snowflake.timestamp);
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
TimonDEV - Github: https://github.com/timondev/sid-generator
up to this point no acknowledgments were made.