finds.dev← search

// the find

ai/nanoid

★ 27,005 · JavaScript · MIT · updated Sep 2026

A tiny (118 bytes), secure, URL-friendly, unique string ID generator for JavaScript

Nano ID is a small JavaScript library that generates random, URL-safe string IDs. The default is 21 characters, which gives roughly the same collision odds as UUID v4 in fewer characters. It suits anyone who wants short IDs for records, DOM nodes or URLs without adding the uuid package or relying on Math.random.

The generator reads from the platform's crypto source (node:crypto or Web Crypto) and maps random bytes onto the alphabet without the modulo bias that a plain random % alphabet introduces. The README says the distribution is tested for uniformity, and the source comments explain each trick, which is rarer than it should be even for a package this small. The API is split sensibly: nanoid for the common case, customAlphabet for fixed alphabets, customRandom when you need to supply the byte source, and a nanoid/non-secure entry point that makes the speed-versus-security choice an explicit import.

The default alphabet includes _ and -, and a hyphen splits words on double-click selection. Teams that need alphanumeric-only IDs have to build that with customAlphabet themselves. customRandom output is not stable across versions, since the README says the random call sequence may change, so seed-based fixtures or deterministic tests can break on upgrade. The library accepts any size without warning, so nanoid(10) passes silently even though the collision math is different, and the README leaves that check to an external calculator. The speed claim rests on a single-machine microbenchmark with no methodology in the README, and the non-secure variant is documented as slower than the secure one, a surprising result the docs do not explain.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →