short-unique-id

Tiny, zero-dependency library for generating random or sequential short UUIDs of any length.

Library
npm
v5.3.2
440stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
37/100Needs Attention
Development Activity0
Maintenance20
Community48
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture76
Code Quality80
Innovation75
Learning Curve90

short-unique-id is a tiny (roughly 6.7 kB minified) library with no runtime dependencies for generating random or sequential short unique IDs of any length. It works in Node.js, the browser, and Deno, ships as both an ES module and CommonJS, and includes a CLI for quick one-off ID generation.

Beyond simple generation, it exposes helpers to reason about collision risk, letting you compute available ID space, approximate the number of IDs before a given collision probability, and derive a uniqueness percentage for a chosen length and dictionary.

What You Get

  • Random and sequential short ID generation with a configurable length
  • Custom or preset dictionaries (alphanumeric, hex, alpha, and more)
  • Collision-probability helpers like availableUUIDs, approxMaxBeforeCollision, and uniqueness
  • A bundled CLI (short-unique-id / suid) for generating IDs from the terminal
  • Universal distribution as ES module and CommonJS with TypeScript types, usable in Node, browsers, and Deno

Common Use Cases

  • Generating short, URL-safe identifiers for links, records, or database keys
  • Producing human-readable IDs shorter than a full 32-character UUID
  • Creating sequential IDs from a fixed dictionary for ordered sequences
  • Estimating collision risk before choosing an ID length for a given volume

Under The Hood

Architecture - The library is a single ShortUniqueId class (src/index.ts, roughly 660 lines) that extends Function so an instance is itself callable. It normalizes the configured dictionary (presets like alphanum, hex, or a user array), tracks a dictIndex counter for sequential generation, and implements rnd()/randomUUID() by sampling the dictionary and seq() for ordered output. Collision math (availableUUIDs, approxMaxBeforeCollision, uniqueness) is derived directly from dictionary length and ID length.

Tech Stack - Written in TypeScript with zero runtime dependencies, built to both ES module and CommonJS targets in dist/, and configured with a modern toolchain (Biome for linting/formatting, TypeDoc for docs). A small bin/ wrapper exposes the CLI, and the package targets Node.js, browsers, and Deno.

Code Quality - The source ships with an inline test file plus a specs suite, uses explicit TypeScript types and interfaces for options, dictionaries, and ranges, and documents the public methods with JSDoc that feeds generated docs. The single-class design keeps the surface small and self-contained.

API Design - The API is compact and discoverable: construct new ShortUniqueId({ length, dictionary }) and call rnd(), randomUUID(), or seq(). Sensible defaults (alphanumeric dictionary, default length) mean zero-config usage works immediately, while the collision helpers give power users the numbers they need to size IDs correctly. The README is thorough with runnable examples and a live RunKit demo.

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

Search