npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@se-oss/snowflake-sequence

v1.0.0

Published

A lightweight TypeScript library for generating and working with Snowflake IDs.

Readme

@se-oss/snowflake-sequence

CI NPM Version MIT License Install Size

A lightweight, high-performance TypeScript library for generating and deconstructing Twitter Snowflake IDs.


❄️ What is a Snowflake ID?

A Snowflake ID is a unique, 64-bit identifier that is highly available and sorted by time. It was developed by Twitter to generate unique IDs for tweets and other objects in their distributed systems. Unlike traditional database sequences, Snowflake IDs are generated without the need for a centralized authority, making them ideal for distributed environments.

A Snowflake ID is composed of the following parts:

  • Timestamp (41 bits): The number of milliseconds since a custom epoch.
  • Node ID (10 bits): A unique identifier for the machine or process generating the ID.
  • Sequence (12 bits): A sequence number that is incremented for each ID generated within the same millisecond.

This structure allows for the generation of up to 4,096 unique IDs per millisecond per node.

✨ Features

  • BigInt Support: Natively handles 64-bit integers for precision and safety.
  • Customizable: Configure node IDs and epochs to suit your distributed system's needs.
  • Deconstruction: Easily extract timestamp, node ID, and sequence from any Snowflake ID.
  • High-Performance: Generates millions of IDs per second.
  • Pure TypeScript: Written entirely in TypeScript with zero dependencies.

📦 Installation

pnpm install @se-oss/snowflake-sequence

📖 Usage

import { Snowflake } from '@se-oss/snowflake-sequence';

// Create a new Snowflake generator with a unique node ID.
const snowflake = new Snowflake({
  nodeId: 1,
  epoch: 1640995200000, // Optional: Jan 1, 2022
});

// Generate a new ID.
const id = snowflake.nextId();
console.log(id);
// => 173242904923537409n

// Deconstruct an ID to get its component parts.
const deconstructed = Snowflake.deconstruct(id);
console.log(deconstructed);
// {
//   timestamp: 1640995200000n,
//   nodeId: 1n,
//   sequence: 1n,
//   epoch: 1288834974657n // The default Twitter epoch
// }

📚 API

new Snowflake(options)

Creates a new Snowflake generator instance.

  • options.nodeId (number): A unique identifier for the node (0-1023). Required.
  • options.epoch (number): A custom epoch timestamp in milliseconds. Optional. Defaults to the Twitter epoch (1288834974657).

snowflake.nextId()

Generates a new Snowflake ID as a bigint.

Snowflake.deconstruct(id)

A static method to deconstruct a Snowflake ID into its component parts.

  • id (bigint): The Snowflake ID to deconstruct.

Returns an object with the following properties:

  • timestamp (bigint)
  • nodeId (bigint)
  • sequence (bigint)
  • epoch (bigint)

🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub

Thanks again for your support, it is much appreciated! 🙏

License

MIT © Shahrad Elahi and contributors.