1.1.0 • Published 2 years ago

@timondev/snowflake-id v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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:

timestampinternal workerIDinternal processIDincrement
42 bits5 bits5bits12bits
uniqueused for clustersused for multiprocesses0 to 4095

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);

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

License

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

Contact

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

Acknowledgments

up to this point no acknowledgments were made.