What is uniku?
uniku is a modern TypeScript library that provides six different ID generation formats in a single, tree-shakeable package. It’s designed to work everywhere: Node.js, Cloudflare Workers, Vercel Edge, Deno, Bun, and browsers.Key Features
Universal Runtime Support
Works everywhere using the Web Crypto API (
globalThis.crypto). No Node.js-specific dependencies.Six ID Formats
UUID v4, UUID v7, ULID, CUID2, Nanoid, and KSUID — all in one library.
Tree-Shakeable
Separate entry points mean you only bundle what you import. No barrel exports.
Byte-Level Access
Convert between ID strings and
Uint8Array with built-in toBytes() and fromBytes().With uniku, you can replace multiple ID generation libraries with a single, optimized package that weighs less than any individual alternative.
Comparison with Other Libraries
| uniku | uuid | nanoid | ulid | cuid2 | ksuid | |
|---|---|---|---|---|---|---|
| UUID v4 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| UUID v7 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| ULID | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ |
| CUID2 | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
| Nanoid | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
| KSUID | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ |
| Tree-shakeable | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
| ESM-only | ✅ | ✅¹ | ✅ | ❌ | ✅ | ❌ |
| Edge/Workers | ✅ | ✅ | ✅ | ⚠️ | ✅ | ⚠️ |
| Byte ↔ String | ✅ | ✅ | - | ⚠️² | - | ✅ |
Notes:
- ¹
uuid@13is ESM-only; earlier versions support CommonJS. - ²
ulidonly provides timestamp encoding/decoding, not full binary serialization. - Byte ↔ String conversion doesn’t make sense for nanoid and cuid2, since they are string-native formats with no canonical binary representation.
Performance
Benchmarks comparing uniku string ID generation with equivalent npm packages:| Generator | uniku vs npm |
|---|---|
| ULID | 85× faster |
| CUID2 | 8× faster |
| KSUID | 1.5× faster |
| UUID v7 | 1.1× faster |
| Nanoid | ~comparable speed |
| UUID v4 | npm is 1.1× faster |
Which ID Should I Use?
Choose the right ID format for your use case:| Use Case | Recommended | Why |
|---|---|---|
| Database primary keys | UUID v7 or ULID | Time-ordered for index efficiency |
| URL shorteners | Nanoid | Compact, URL-safe characters |
| Prevent enumeration | CUID2 | Non-sequential, secure |
| Maximum compatibility | UUID v4 | Universal standard |
| Distributed systems | ULID | Sortable + high entropy |
Detailed Comparison
UUID v7 (Recommended for most use cases)- Time-ordered with millisecond precision
- 128-bit (16 bytes)
- Lexicographically sortable
- Follows RFC 9562 standard
- Ideal for database primary keys
- Purely random
- 122 bits of entropy
- Most widely supported
- No time ordering
- Time-ordered with millisecond precision
- 128-bit (16 bytes)
- Crockford Base32 encoded (URL-safe)
- Lexicographically sortable
- More compact string representation than UUID
- Non-sequential to prevent enumeration
- Uses SHA3-512 hashing
- Configurable length (2-32 characters)
- No timestamp component
- Best when you need unpredictability
- 21 characters by default
- URL-safe alphabet
- Customizable size and alphabet
- No time ordering
- Smallest string representation
- Time-ordered with second precision
- 160-bit (20 bytes)
- Base62 encoded
- Lexicographically sortable
- Good for distributed systems
Works Everywhere
uniku uses the Web Crypto API (globalThis.crypto), which means it works in all modern JavaScript environments:
- Node.js (v24.13.0+)
- Deno
- Bun
- Cloudflare Workers
- Vercel Edge Functions
- Modern Browsers
Why Choose uniku?
- Modern Architecture: ESM-only, no legacy CommonJS support
- Universal Compatibility: Works in all JavaScript runtimes
- Truly Tree-Shakeable: Separate entry points, no barrel exports
- Byte-Level Control: Full binary serialization support
- Production Ready: Battle-tested with comprehensive test coverage
- Lightweight: Designed for performance-sensitive contexts like ORMs
Next Steps
Installation
Get started by installing uniku in your project
Quick Start
Generate your first ID in under 5 minutes
