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

ksort-id

v1.0.1

Published

A high-performance, K-sortable, zero-dependency ID generator for Node.js.

Readme

ksort-id (High-Performance ID Generator)

A zero-dependency, K-Sortable, and URL-safe random ID generator for Node.js and TypeScript. Designed to replace uuid and nanoid in all major and minor usages.

npm version License: MIT TypeScript

Why use this?

The Problem with UUIDs

Standard UUIDs (v4) are completely random. When you insert them into a database (MySQL/PostgreSQL), they scatter across the B-Tree index, causing Index Fragmentation and slowing down insertion speeds as your data grows.

The Solution: K-Sortability

ksort-id generates IDs that are Time-Ordered.

  • New IDs > Old IDs (lexicographically).
  • Database inserts always happen at the "end" of the index.
  • Result: ~50% faster database writes compared to UUIDv4 at scale.

Inspired by Twitter's Snowflake ID generation system, ksort-id provides globally unique, time-ordered IDs that ensure efficient database performance and scalability.


Installation

npm install ksort-id

Usage

The library exposes two modes: Sortable (for Databases) and Pure Random (for Tokens).

  1. Database Keys- Best for Primary Keys, User IDs, and Order ID.
import { sortid } from 'ksort-id';

const id = sortid(); 
// Output: "001iU5yV9b2n5k1lX0z"
// Structure: [Timestamp (8 chars)] + [Randomness (12 chars)]
  1. Tokens & Short Links- Best for URL Shorteners, API Keys, and Invite Codes.
import { randomid } from 'ksort-id';

const token = randomid(6); 
// Output: "aZ91x7"
// Structure: Pure Randomness

API Reference

sortid(config?: IdConfig): string

Generates a time-ordered, sortable ID optimized for database operations.

Parameters:

  • config.length? (number) - Total ID length in characters

Defaults & Constraints:

  • Default Length: 20 characters (8 timestamp + 12 random)
  • Minimum Length: 9 characters (must be greater than 8 to ensure uniqueness)

Examples:

sortid();                    // Default: "001iU5yV9b2n5k1lX0z" (20 chars)
sortid({ length: 25 });      // Custom: 25 character sortable ID

randomid(length?: number): string

Generates a pure random string with no ordering properties.

Parameters:

  • length? (number) - Total ID length in characters

Defaults & Constraints:

  • Default Length: 21 characters
  • Minimum Length: 1 character

Examples:

randomid();           // Default: "aZ91x7K2mP8qR4tV0w" (21 chars)
randomid(6);          // Short: "aZ91x7" (6 chars)
randomid(50);         // Long: 50 character random string

Architecture

  • Zero Dependencies: No bloat. 100% Native.

  • Buffer Pooling: Pre-allocates random bytes to minimize System Calls and Garbage Collection.

  • Base62 Encoding: Custom integer-to-string implementation optimized for V8.