Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sonyflake

thedv917.1kMIT1.1.2TypeScript support: included

A modern implementation Sonyflake on TypeScript

snowflake, sonyflake, twitter, bigint, typescript, generator

readme

Sonyflake - A modern implementation Sonyflake on TypeScript

📖 Documentation

Installation

Node.js 10.16.0 or newer is required

Yarn

Recommended

yarn add sonyflake

NPM

npm i sonyflake

Example usage

import { Sonyflake, Epochs } from 'sonyflake';

const sonyflake = new Sonyflake({
  machineId: 2, // in range 2^16
  epoch: Date.UTC(2020, 4, 18, 0, 0, 0), // timestamp
});

const snowflake = sonyflake.nextId();

console.log(snowflake); // => "1211144891006978"

const deconstructSnowflake = sonyflake.deconstruct(snowflake);

console.log(deconstructSnowflake); // =>
// { timestamp: 1589832189861,
//     machineId: 2,
//     sequence: 0 }

changelog

sonyflake

1.2.0

Minor Changes

  • 77c03e6: Update package