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

universal-snowflake-id

v0.1.3

Published

Universal Snowflake ID generator for Node.js, Browsers, Deno, and Bun. Base62 encoded.

Downloads

6

Readme

Universal Snowflake ID

⚡️ Lightweight, dependency-free, Snowflake ID generator with base62 encoding for Node.js, Deno, Bun, and browsers.

npm version build license


✨ Features

  • ⚡️ High performance, 64-bit Snowflake ID generator
  • 🌐 Universal: Works in Node.js, Bun, Deno, and modern browsers
  • 🔢 Base62 encoding for shorter, URL-friendly IDs
  • 📦 Supports CJS, ESM, and UMD module formats
  • 🗓️ Supports custom or predefined epochs (Twitter, Discord, or your own)
  • 🛠 No external dependencies

📦 Installation

# Bun
bun add universal-snowflake-id

# npm
npm install universal-snowflake-id

# yarn
yarn add universal-snowflake-id

# pnpm
pnpm add universal-snowflake-id

🚀 Usage

Basic

import { Snowflake } from "universal-snowflake-id";

const snowflake = new Snowflake({
  datacenterId: 1,
  machineId: 1,
});

const id = snowflake.generate(); // bigint
const shortId = snowflake.generateBase62(); // string

Use with predefined epochs

import { Snowflake } from "universal-snowflake-id";

const discordSnowflake = new Snowflake({
  datacenterId: 1,
  machineId: 1,
  epoch: "discord",
});

const twitterSnowflake = new Snowflake({
  datacenterId: 1,
  machineId: 1,
  epoch: "twitter",
});

Environment-based default instance

import snowflake from "universal-snowflake-id";

// Uses env vars: SN_DATACENTERID, SN_MACHINEID, SN_EPOCH
const id = snowflake.generateBase62();

SN_EPOCH can be a number, discord, or twitter.


🔢 API

new Snowflake(options)

| Option | Type | Description | | -------------- | ---------------------------------- | ------------------------------------------- | | datacenterId | number (0–31) | Required – identifies the datacenter | | machineId | number (0–31) | Required – identifies the machine within DC | | epoch | number \| "discord" \| "twitter" | Optional – default is current timestamp |

generate(): bigint

Returns a new Snowflake ID as a bigint.

generateBase62(): string

Returns a new Snowflake ID as a short base62 string.

parseBase62(str: string): bigint

Decodes a base62 string back to its original bigint.


📚 Predefined Epochs

| Name | Description | Value | | --------- | ------------------------- | --------------- | | twitter | Twitter's Snowflake epoch | 1288834974657 | | discord | Discord's Snowflake epoch | 1420070400000 |


🧪 Testing

bun test

You can also use Node or Vitest if preferred.


📦 Build

bun run build

Generates dist/ folder with CJS, ESM, and UMD builds using microbundle.


🚀 Releasing

This project uses release-it with GitHub Actions:

bunx release-it

This:

  • Bumps version
  • Builds the package
  • Publishes to npm
  • Creates GitHub tag/release (if configured)

👷 CI/CD

  • Automatically builds and publishes on GitHub tag push
  • GitHub Actions config in .github/workflows/release.yml

📁 Output

Built with microbundle, output includes:

  • dist/index.cjs.js
  • dist/index.esm.js
  • dist/index.umd.js
  • dist/index.d.ts (types)

🪪 License

MIT © @amiry-jd


💡 Inspiration

Inspired by Twitter/Discord Snowflake implementations and ID generation needs in modern distributed systems.