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

zero-id

v0.0.8

Published

A clean and efficient unique identifier

Readme

Zero ID

A compact, time-sortable unique identifier for JavaScript and TypeScript.

Installation

npm install zero-id

Usage

import {
  zeroId,
  zeroIdAt,
  batch,
  decodeZeroId,
  isValidZeroId,
  compareZeroIds,
  extractTimestamp,
  getAge,
  isBefore,
  isAfter,
  extractPrefix,
  getTimestampRange,
  toBuffer,
  fromBuffer,
  toUUID,
  fromUUID,
  constants,
} from "zero-id";

Core Functions

zeroId(options?)

Generate a unique ID.

const id = zeroId();
// => "4kN7pQ2xR8mB5vLw"

const userId = zeroId({ prefix: "user_" });
// => "user_4kN7pQ2xR8mB5vLw"

const orderId = zeroId({
  prefix: "order_",
  randomLength: 10,
  metadata: { amount: 99.99, currency: "USD" },
  checksum: true,
});

zeroIdAt(timestamp, options?)

Generate an ID with a specific timestamp.

const id = zeroIdAt(1700000000000);
const id = zeroIdAt(new Date("2024-01-15"));
const id = zeroIdAt(Date.now() - 86400000, { prefix: "old_" });

batch(count, options?)

Generate multiple IDs at once.

const ids = batch(100);
const userIds = batch(50, { prefix: "user_" });

decodeZeroId(id, prefix?, options?)

Decode an ID to get its timestamp, creation date, and metadata.

const decoded = decodeZeroId(id);
// => { timestamp: 1634567890123, createdAt: Date(...), metadata: undefined }

const decoded = decodeZeroId(orderId, "order_");
// => { timestamp: ..., createdAt: Date(...), metadata: { amount: 99.99, currency: "USD" } }

const decoded = decodeZeroId(id, "", { checksum: true });

isValidZeroId(id, prefix?, options?)

Check if an ID is valid.

isValidZeroId(id); // => true
isValidZeroId(userId, "user_"); // => true
isValidZeroId(checksumId, "", { checksum: true }); // => true

compareZeroIds(a, b, prefix?)

Compare two IDs for sorting.

ids.sort(compareZeroIds);
ids.sort((a, b) => compareZeroIds(a, b, "user_"));

Time Utilities

extractTimestamp(id, prefix?)

Get the timestamp without full decode.

const timestamp = extractTimestamp(id);
// => 1634567890123

getAge(id, prefix?)

Get the age of an ID in milliseconds.

const age = getAge(id);
// => 3600000 (1 hour)

isBefore(id, date, prefix?) / isAfter(id, date, prefix?)

Check if an ID was created before/after a specific time.

const cutoff = new Date("2024-01-01");
const oldIds = ids.filter((id) => isBefore(id, cutoff));
const newIds = ids.filter((id) => isAfter(id, cutoff));

isBefore(id, Date.now() - 86400000); // created more than 1 day ago?

getTimestampRange(ids, prefix?)

Get the time range of a collection of IDs.

const range = getTimestampRange(ids);
// => { oldest: 1700000000000, newest: 1700005000000, oldestDate: Date(...), newestDate: Date(...), span: 5000000 }

Prefix Utilities

extractPrefix(id, knownPrefixes?)

Extract the prefix from an ID.

extractPrefix("user_4kN7pQ2xR8mB5vLw");
// => "user_"

extractPrefix("4kN7pQ2xR8mB5vLw");
// => null

extractPrefix("user_abc123", ["user_", "order_"]);
// => "user_"

Conversion Utilities

toBuffer(id, prefix?) / fromBuffer(buffer, prefix?)

Convert to/from binary format for compact storage.

const buffer = toBuffer(id);
const restored = fromBuffer(buffer);

toUUID(id, prefix?) / fromUUID(uuid, prefix?)

Convert to/from standard UUID format.

const uuid = toUUID(id);
// => "550e8400-e29b-41d4-a716-446655440000"

const id = fromUUID(uuid);

Constants

import { constants } from "zero-id";

constants.TIMESTAMP_LENGTH; // 9
constants.DEFAULT_RANDOM_LENGTH; // 7
constants.BASE62_CHARS; // "0123456789ABC...xyz"
constants.MIN_TIMESTAMP; // 946684800000 (year 2000)
constants.MAX_TIMESTAMP; // 32503680000000 (year 3000)

Options Reference

interface ZeroIdOptions<T> {
  prefix?: string; // Prefix to prepend (e.g., "user_")
  randomLength?: number; // Random part length (default: 7)
  metadata?: T; // Metadata object to embed
  checksum?: boolean; // Add 2-char checksum for validation
}

Format

| Part | Length | Description | | ---------- | -------- | ---------------------------- | | Prefix | Variable | Optional (e.g., "user_") | | Timestamp | 9 chars | Base62 encoded milliseconds | | Metadata | Variable | Optional, length-prefixed | | Random | 7 chars | Configurable random data | | Checksum | 2 chars | Optional validation checksum |

Base62 encoding (0-9, A-Z, a-z) - URL-safe, no special characters.

License

MIT