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

small-uid

v0.3.4

Published

Small UIDs are lexicographically sortable short (64bit) unique identifiers designed to be used as an efficient database Primary Key and a readable (11/12 characters) URL safe UID when encoded.

Downloads

204

Readme

Small UID

GitHub License GitHub License GitHub branch check runs Crates.io Version JSR NPM Version FOSSA Status FOSSA Status

Small UID is a small, url-safe, user-friendly unique, lexicographically sortable id generator.

UUIDs are frequently used as database Primary Key in software development. However, they aren't the best choice mainly due to their random sorting and the resulting fragmentation in databases indexes.

Using ULIDs is generally a very good alternative, solving most of UUID flaws.

Twitter's Snowflake is another option if you want to generate roughly sortable uid. But, Snowflake is not using random numbers instead it used machine id to generate the uid. It's a good choice if you integrate it into a distributed systems and doesn't really need randomness.

Small UIDs are also an ideal alternative when you do not need as much uniqueness and want shorter "user-friendly" encoded strings.

Introduction

Small UIDs are short unique identifiers especially designed to be used as efficient database Primary Key:

  • Half smaller than UUID / ULID (64-bit)
  • Lexicographically sortable
  • Encodable as a short user-friendly and URL-safe base-64 string (a-zA-Z0-9_-)
  • User-friendly strings are generated in a way to be always very different (no shared prefix due to similar timestamps)

| | Small UID | ULID | UUID v4 | | ------------------------- | :-----------------: | :-------------------: | :-------: | | Size | 64 bits | 128 bits | 128 bits | | Monotonic sort order | Yes *** | Yes | No | | Random bits | 20 | 80 | 122 | | Collision odds ** | 1,024 / ms* | 1.099e+12 / ms* | 2.305e+18 |

* theorical number of generated uids before the first expected collision.
** the uid includes a timestamp, so collisions may occur only during the same millisecond.
*** monotonic sort order, but random order when generated at the same millisecond.

They are internally stored as 64-bit integers (44-bit timestamp followed by 20 random bits):

|-----------------------|  |------------|
        Timestamp            Randomness
         44 bits               20 bits

The random number suffix still guarantees a decent amount of uniqueness when many ids are created in the same millisecond (up to 1,048,576 different values) and you may only expect collision if you're generating more than 1024 random ids during the same millisecond.

Sorting

Because of the sequential timestamp, Small UIDs are naturally sorted chronologically. It improves indexing when inserting values in databases, new ids being appended to the end of the table without reshuffling existing data (read more in this article).

However, sort order within the same millisecond is not guaranteed because of the random bits suffix.

Guaranteed monotonicity for javascript version is planned.

This project is loose reimplementation of Small-UID by Mediagone with the only difference is the string encoding for this one is base64-url instead of base62 for enabling wider usecases.

Typescript

For cloudflare worker you should use the pure js version.

Documentation in JSR

Example

Generating Small UID

import { SmallUid } from "small-uid";
// import { SmallUid } from "small-uid/pure";

const uid = SmallUid.gen();
console.log(uid.string); // prints the base64url encoded string
console.log(uid.value); // prints the underlying integer value

Using other RNG implementations

// Os rng, slow but secure
const uid = SmallUid.gen("secure");
// CSPRNG, fast and reasonably secure. Same as default.
const uid = SmallUid.gen("secure_fast");
// Using Math.random(), fast but insecure
const uid = SmallUid.gen("insecure");

Generating Small UID from a 64-bit integer

const smallUidValue: bigint = 0x123456789abcdefn;
const uid = new SmallUid(smallUidValue);
console.log(uid.string); // prints the base64url encoded string
console.log(uid.value); // prints the underlying numeric value

Generating Small UID from a string

const smallUidString = "XxXxXxXxXxX";
const uid = new SmallUid(smallUidString);
console.log(uid.string); // prints the base64url encoded string
console.log(uid.value); // prints the underlying numeric value