JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1422
  • Score
    100M100P100Q116106F
  • License MIT

A modern implementation Snowflake on TypeScript

Package Exports

  • snowyflake

Readme

NPM version Build Status NPM downloads

Snowyflake - A modern implementation Snowflake on TypeScript

📖 Documentation

Installation

Node.js 16.0.0 or newer is required

TypeScript config required "target": "ES2019" or higher

Yarn

Recommended

yarn add snowyflake

NPM

npm i snowyflake

Example usage

import { Snowyflake, Epoch } from 'snowyflake';

const snowyflake = new Snowyflake({
    workerId: 1n,
    epoch: Epoch.Twitter // BigInt timestamp
});

const snowflake = snowyflake.nextId();

console.log(snowflake); // => 1075766315999952896n

const deconstructSnowflake = snowyflake.deconstruct(snowflake);

console.log(deconstructSnowflake); // =>
// { timestamp: 1545317651163n,
//     workerId: 1n,
//     processId: 0n,
//     sequence: 0n }