Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sapphire/snowflake

Package Overview
Dependencies
Maintainers
3
Versions
882
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sapphire/snowflake

Deconstructs and generates snowflake IDs using BigInts

  • 3.5.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is @sapphire/snowflake?

@sapphire/snowflake is a utility library for generating and parsing unique snowflake IDs, which are often used in distributed systems to ensure unique identifiers. It is particularly useful in applications that require high-scale, unique ID generation.

What are @sapphire/snowflake's main functionalities?

Generate Snowflake ID

This feature allows you to generate a unique snowflake ID. The generated ID is a 64-bit integer that is unique and can be used as an identifier in distributed systems.

const { Snowflake } = require('@sapphire/snowflake');
const snowflake = new Snowflake();
const id = snowflake.generate();
console.log(id);

Parse Snowflake ID

This feature allows you to parse a snowflake ID to extract its components, such as the timestamp, worker ID, and process ID. This can be useful for debugging or analyzing the IDs.

const { Snowflake } = require('@sapphire/snowflake');
const snowflake = new Snowflake();
const id = snowflake.generate();
const parsed = snowflake.deconstruct(id);
console.log(parsed);

Custom Epoch

This feature allows you to set a custom epoch for the snowflake ID generation. The epoch is the starting point for the timestamp component of the ID, and setting a custom epoch can be useful for aligning IDs with specific events or timeframes.

const { Snowflake } = require('@sapphire/snowflake');
const customEpoch = 1609459200000; // Custom epoch (e.g., January 1, 2021)
const snowflake = new Snowflake(customEpoch);
const id = snowflake.generate();
console.log(id);

Other packages similar to @sapphire/snowflake

Keywords

FAQs

Package last updated on 19 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc