cuid2

Secure, collision-resistant unique IDs for JavaScript, built to resist guessing and horizontal-scale collisions.

Library
npm
v3.3.0
3,406 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
43 /100 Fair
Development Activity 24
Maintenance 4
Community 52
Maturity 52
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 78
Code Quality 78
Innovation 72
Learning Curve 55

Cuid2 is a next-generation unique ID generator built as a security-conscious replacement for UUIDs and the original Cuid. Instead of relying on a single entropy source, it combines the current timestamp, a session counter, a host fingerprint, and cryptographically secure random values, then mixes them through a NIST-standard SHA3 hash so the output reveals nothing about how or when it was created.

The library ships as a tiny, dependency-light ESM package with zero async operations, making it safe to call in hot paths across Node.js and browser environments. It also includes a CLI (npx @paralleldrive/cuid2) for generating ad-hoc IDs and slugs from the terminal, and an isCuid validator for checking existing values. With over 19 million weekly downloads, it’s a common choice for primary keys, request IDs, and other identifiers that need to be generated client-side without a database round trip.

What You Get

  • createId() — a zero-config function that returns a 24-character, lowercase alphanumeric identifier ready to use as a primary key or public-facing ID
  • init(options) — a configurable factory that lets you set a custom id length (2-32 chars), a custom fingerprint, or a custom random function (e.g. a CSPRNG)
  • isCuid(id, options) — a validator to check whether a string matches the expected cuid2 shape and length constraints
  • A CLI (npx @paralleldrive/cuid2) for generating one or many ids or short slugs directly from the terminal, with an optional shell alias installer
  • TypeScript type definitions (index.d.ts) shipped in the package, so consumers get full type safety with no extra @types install

Common Use Cases

  • Generating primary keys for database rows created on the client before an insert, avoiding a round trip just to obtain an id
  • Producing public-facing resource identifiers (e.g. in URLs) that don’t leak creation order or timing the way sequential or k-sortable ids do
  • Creating short, human-shareable slugs (via a reduced length) for use cases like disambiguating usernames or short links
  • Generating request/correlation ids in distributed systems where multiple hosts must produce non-colliding ids without a shared counter or lock

Under The Hood

Architecture

The library is a flat, single-module design centered on src/index.js, built as a small functional pipeline rather than a class hierarchy: createRandom picks between the Web Crypto API and Math.random as the entropy source, createEntropy and createFingerprint derive salt and host-identity strings, and init() closes over a counter, fingerprint, and random function to return a per-call id generator. The default createId export is a lazily-initialized singleton (via a small lazy(fn) wrapper) so fingerprint/counter setup is deferred until first use. The root index.js is a thin re-export layer over src/index.js, and bin/cuid2.js is a separate CLI entry point that imports the built index.js and translates argv flags into init() options. There is no deeper layering — changing the hash() function or the order entropy sources are concatenated in would change the shape of every id the library produces.

Tech Stack

The package is distributed as ESM only ("type": "module" with an exports map) and depends on @noble/hashes for an audited SHA3-512 implementation and bignumber.js to convert hash bytes into a big integer for base36 encoding. A separate error-causes dependency is used only in the maintainers’ own release.js script, not in the published library code. Build/release tooling includes ESLint 9 (flat config) with Prettier, a Husky pre-commit hook, and release-it for versioning. The repository also bundles a small Next.js app (next.config.js, pages/) used for a companion demo/visualization site (histogram and randogram pages), which is excluded from the published npm package via the files allowlist in package.json.

Code Quality

Tests live in src/index-test.js and src/bin-test.js, run directly with node using the riteway library’s given/should/actual/expected assertion style rather than a full test-runner framework. Beyond unit tests, the repo includes src/collision-test.js and src/histogram.js, which generate millions of ids across parallel processes and check the output distribution for statistical bias — a notably more rigorous validation approach than most id-generation libraries ship with. Hand-authored TypeScript definitions (index.d.ts) cover the public API and are checked against the test file via a dedicated tsc script. A GitHub Actions workflow (.github/workflows/ci.yml) runs checks on push, and ESLint/Prettier/Husky enforce style locally. Error handling is minimal but explicit — init() throws a descriptive Error when an invalid length is requested.

What Makes It Unique

Cuid2’s real innovation isn’t a new algorithm class but a deliberate entropy-composition strategy: it mixes a timestamp, a randomly-seeded session counter, a hashed host fingerprint, and CSPRNG output through a single NIST-standard hash function, and is intentionally tuned to not be maximally fast, since very fast id generation makes brute-force collision- and pattern-hunting attacks cheaper. That’s a different design goal than speed-optimized alternatives like nanoid or UUID v4, which don’t treat generation speed itself as an attack surface. It’s best understood as a thoughtful, security-focused evolution of the original Cuid rather than a groundbreaking new technique, but it fills a specific, well-articulated niche that most alternatives don’t target.

Used by 17 apps in this directory

Rust
60%
Apache 2.0

Magnitude

AI Development · Developer Tools

7,313

An open source inference engine that profiles your hardware, recommends the best local models, and tunes them for the coding agent you already use.

View details
79
Repo Health
83
Technical
71
Dependency
Built with
Rust 60%
TypeScript 25%
Updated 1 weeks ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 1 weeks ago
TypeScript
94%
AGPL 3.0

Papra

Bookmarks Archiving

5,587

Self-hosted document archiving with email ingestion, OCR full-text search, and pluggable storage — store once, find anything.

View details
86
Repo Health
82
Technical
69
Dependency
Built with
TypeScript 94%
Updated 1 weeks ago
TypeScript
96%
Other

Refly

AI Development · Automation · No Code Platforms

7,537

Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.

View details
68
Repo Health
76
Technical
63
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
98%
MIT

sigle

Blogging

489

A decentralized, open-source writing platform that permanently stores your stories on the Stacks blockchain and Arweave — where Web3 content creators own their words forever.

View details
81
Repo Health
78
Technical
69
Dependency
Built with
TypeScript 98%
Updated 2 weeks ago
TypeScript
89%
Other

strapi

CMS

73,368

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
63
Dependency
Built with
TypeScript 89%
JavaScript 11%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,119

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
64
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
65%
Other

Typebot

AI Assistants · AI Development · Developer Tools

10,576

Build sophisticated chatbots visually, embed them anywhere without iframes, and own your data — fully self-hostable with a modular block system and 30+ integrations.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 65%
MDX 34%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers