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

crypto-id

v0.3.2

Published

Create a random id of any length with characters 0-9,A-Z,a-z using the browser's crypto.getRandomValues interface.

Readme

Crypto ID

Create cryptographically secure random alphanumeric IDs and sortable identifiers using the browser crypto API.

Installation

npm install crypto-id

Features

  • 🔐 Cryptographically secure - Uses crypto.getRandomValues()
  • 🌐 Universal - Works in browsers and Node.js
  • 📝 URL-safe - Base 62 encoding (0-9, A-Z, a-z)
  • Fast - Efficient rejection sampling for uniform distribution
  • 🕒 Sortable IDs - Timestamp-based IDs with lexicographical sorting
  • 📦 Lightweight - No dependencies

API

createId(length?: number): string

Creates a cryptographically secure random ID of any length.

import { createId } from 'crypto-id';

createId();     // "RJPoz4veOGn9nbDI" (16 chars, ~4.7e28 possibilities)
createId(12);   // "GS7rPnA0mmbv" (~3.22e21 possibilities)
createId(4);    // "vMH6" (~14.7M possibilities)

Parameters:

  • length (optional): Length of the ID (default: 16)

Returns: Random alphanumeric string

The number of possible IDs is 62^length.

createSortableId(): string

Creates a sortable identifier that's lexicographically ordered by creation time.

import { createSortableId } from 'crypto-id';

createSortableId(); // "0UmdJLiDuEbwhJfL" (16 chars, sortable by time)
createSortableId(); // "0UmdJLiDuEbwhJfM" (increments if same millisecond)

Returns: 16-character sortable identifier

Sortable ID Format

Our sortable IDs use the format: TTTTTTTTRRRRRRRR

  • 8 characters: Timestamp (base 62 encoded milliseconds, good until year 8888)
  • 8 characters: Random component
Example: 0UmdJLiDuEbwhJfL
         ┬───────┬───────
         │       └─ Random (8 chars)
         └──────── Timestamp (8 chars)

This ensures:

  • ✅ Lexicographical sorting matches chronological order
  • ✅ No collisions within the same millisecond
  • ✅ Optimal database indexing performance

What Makes These Special?

🎯 Universally Unique

With 62⁸ random combinations per millisecond, collisions are astronomically unlikely.

📊 Database Friendly

  • Lexicographically sortable by creation time
  • Excellent for database indexing
  • Better performance than UUIDs for time-ordered data

🔒 Cryptographically Secure

Both functions use secure random generation, making IDs unpredictable and safe for security-sensitive applications.

Optimized for Reality

  • Extensive timestamp range (until year 8888)
  • Excellent collision resistance (2.18×10¹⁴ combinations/ms)
  • Compact 16-character format

Monotonicity

Sortable IDs handle multiple generations within the same millisecond:

// Same millisecond - automatic increment
const id1 = createSortableId(); // "0UmdJLiDuEbwhJfL"
const id2 = createSortableId(); // "0UmdJLiDuEbwhJfM"
const id3 = createSortableId(); // "0UmdJLiDuEbwhJfN"

// Different millisecond - fresh random component
// (after delay)
const id4 = createSortableId(); // "0UmdJLiEX87wJp4H"

This ensures:

  • ✅ Lexicographical sorting matches chronological order
  • ✅ No collisions within the same millisecond
  • ✅ Optimal database indexing performance

Performance

  • createId: Pure random generation, fastest
  • createSortableId: Timestamp + monotonicity handling, minimal overhead

Both functions use efficient rejection sampling for uniform distribution and batch random byte generation for optimal performance.

Browser and Node.js Support

Works seamlessly in both environments:

  • Browser: Uses crypto.getRandomValues()
  • Node.js: Uses crypto.webcrypto.getRandomValues()

TypeScript

Full TypeScript support included with comprehensive type definitions.

import { createId, createSortableId } from 'crypto-id';

const randomId: string = createId(12);
const sortableId: string = createSortableId();

Development

This package includes a comprehensive test suite that covers all functionality:

# Run tests
npm test

# Build TypeScript
npm run build

# Build and test (runs automatically before publishing)
npm run prepare

The test suite verifies:

  • ✅ Correct ID lengths and formats
  • ✅ Base 62 character set usage
  • ✅ Uniqueness and collision resistance
  • ✅ Sortable ID monotonicity and ordering
  • ✅ Timestamp progression over time