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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kirick/snowflake

v0.3.1

Published

Generator of unique & sortable IDs.

Readme

@kirick/snowflake

npm version License: MIT

Generator of unique & sortable IDs based on the Snowflake IDs algorithm.

Features

  • 🔄 Distributed: Generate IDs across multiple servers without coordination
  • 📊 Sortable: IDs are time-ordered for easy sorting with default JS operators and indexing
  • 🔄 Multiple formats: Use Snowflakes as ArrayBuffer, Buffer, BigInt, as well as decimal, hexadecimal, and base62 strings
  • 🔍 TypeScript: Fully typed API for improved developer experience
  • 🛠️ Customizable: Configure server/worker bits to suit your infrastructure

How It Works

Snowflake IDs are 64-bit values structured as follows:

+-----------+--------+--------+-----------+
| timestamp | server | worker | increment |
| 42 bits   | 7 bits | 5 bits | 10 bits   |
+-----------+--------+--------+-----------+

The actual bit allocation for server and worker can be adjusted using the bits option in the constructor.

  • Timestamp: Milliseconds since January 1, 2022
  • Server ID: Identifies the server instance
  • Worker ID: Identifies the worker process on the server
  • Increment: Sequence number for IDs generated in the same millisecond

Installation

bun install @kirick/snowflake
# or
pnpm install @kirick/snowflake
# or
npm install @kirick/snowflake

Usage

Basic Usage

import { SnowflakeFactory } from '@kirick/snowflake';

// Create a factory with custom server and worker IDs
const factory = new SnowflakeFactory({
  server_id: 3,
  worker_id: 2
});

// Generate a new snowflake ID
const snowflake = factory.create();

// Convert to different formats
console.log(snowflake.toDecimal()); // "197388558662189056"
console.log(snowflake.toHex());     // "02be35da5e810042"
console.log(snowflake.toBase62());  // "3fMxtObVhma"
console.log(snowflake.toBigInt());  // 197388558662189056n

// Extract components
console.log(snowflake.timestamp); // 1690123456789
console.log(snowflake.server_id); // 3
console.log(snowflake.worker_id); // 2
console.log(snowflake.increment); // 0

Custom Bit Allocation

Customize how bits are allocated between server ID, worker ID, and increment counter to match your specific infrastructure needs. This feature allows you to optimize the Snowflake algorithm for different scaling patterns:

  • Horizontal Scaling: Allocate more bits to server ID when deploying across many physical servers or cloud instances;
  • Vertical Scaling: Allocate more bits to worker ID when running many workers on fewer, more powerful machines;
  • High-Frequency Generation: Reduce server/worker bits to allow for more increments per millisecond when generating many IDs on a single node.

The total available bits for customization is fixed at 22 bits (the remaining 42 bits are reserved for the timestamp). Increasing one value means decreasing another, allowing you to make tradeoffs based on your architecture.

import { SnowflakeFactory } from '@kirick/snowflake';

// Customize bit allocation for different scaling needs
const factory = new SnowflakeFactory({
  bits: {
    server_id: 10, // 10 bits = up to 1024 servers
    worker_id: 6   // 6 bits = up to 64 workers per server
    // there are 5 bits left for increment counter
    // so, 32 snowflakes can be created per millisecond per worker per server
  },
  server_id: 42,
  worker_id: 7
});