@ultimatelemoneu/snowflake

1.0.1 • Public • Published

UltimateLemon Snowflake ☃️



About 📘

This repository households the source code for the UltimateLemon Snowflake package. We utilize Twitter's snowflake ❄️ format for uniquely identifiable descriptors (IDs).

Snowflake architecture ☃️

Snowflake IDs are 64-bit unsigned integers that are roughly sortable by time. Because of their length, snowflakes are always stored as strings. Snowflakes are composed of 4 parts:

  • Timestamp, milliseconds since 1 January 2023 00:00:00 UTC
  • Internal worker ID
  • Internal process ID
  • Increment, for every ID that is generated on that process

Installation 📦

# With npm
npm install @ultimatelemoneu/snowflake

# With yarn
yarn add @ultimatelemoneu/snowflake

Usage 🚀

Create new snowflake

It is time to create your first snowflake ID. You can do this by creating a new instance of the Snowflake class and calling the generate method.

import Snowflake from '@ultimatelemoneu/snowflake';

const snowflake = new Snowflake();

// You can use this ID variable to identify a user, a message, a channel, etc.
const id = snowflake.generate();

Parse existing snowflakes

You can also parse existing snowflakes. This is useful when you want more information about a snowflake ID.

import Snowflake from '@ultimatelemoneu/snowflake';

const snowflakeInfo = Snowflake.parse('131557566537793536');
// {
//   createdAt: 2023-01-01T00:00:00.000Z,
//   workerId: 0,
//   processId: 0
// }

License 📜

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

Package Sidebar

Install

npm i @ultimatelemoneu/snowflake

Weekly Downloads

0

Version

1.0.1

License

LGPL-3.0-only

Unpacked Size

52 kB

Total Files

11

Last publish

Collaborators

  • hallosouf
  • itisjusty