Giter Site home page Giter Site logo

snowflakegenerator's Introduction

SnowflakeGenerator

Twitter snowflake generator in pure javascript.

Tutorial

  1. Create a new SnowflakeGenerator object
  2. Call id to generate a new id
const snowflakeGenerator = new SnowflakeGenerator();

snowflakeGenerator.id; // New generated snowflake
snowflakeGenerator.id; // New generated snowflake. Different to the snowflake that got generated before

Docs

Key Type Required Default Description
epoch bigint no 1609459201000n The epoch that indicates the start of the snowflakes timestamp
worker bigint no 1n The worker's id. The ID of the datacenter or server can be used as well
process bigint no 1n The process id.
accumulator bigint no 0n The increment id or accumulator that indicates the snowflake's id from their respectiv process, worker and epoch

Properties

Get one new generated snowflake

Returns: string

Example:

const snowflake = snowflakeGenerator.id;

Methods

Generate 1 or more snowflakes

Parameter Type Required Default Description
amount number no 1 The amount of snowflakes you want to generate

Returns: Array<string> | string

Example:

const snowflake = snowflakeGenerator.next();

Generate a new snowflake as a bigint

Returns: bigint

Example:

const snowflake = snowflakeGenerator.generateId();

snowflakegenerator's People

Contributors

xander1233 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

kveratis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.