Skip to content

Latest commit

 

History

History
138 lines (98 loc) · 3.83 KB

README.md

File metadata and controls

138 lines (98 loc) · 3.83 KB

Snowflake ID Generator

ID Generator and deconstructor by TimonDEV.
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Contributing
  4. License
  5. Contact
  6. Acknowledgments

About The Project

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

(back to top)

Getting Started

To get a started with this project follow these simple steps.

Prerequisites

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

Installation & Usage

  1. Install the package using the following command:

    npm install @timondev/snowflake-id
  2. Try out the following example:

    import { SnowflakeID } from '@timondev/snowflake-id';
    
    let id = SnowflakeID.generate();
    
    console.log(`Snowflake generated the following id ${id}`);
  3. Or use it to deconstruct snowflakes:

    import { SnowflakeID } from '@timondev/snowflake-id';
    
    let id = '86913608335773696';
    let snowflake = new SnowflakeID(id);
    
    console.log(snowflake.timestamp);

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

TimonDEV - Github: https://github.com/timondev/sid-generator

(back to top)

Acknowledgments

up to this point no acknowledgments were made.

(back to top)