Skip to main content
uniku /uˈniːku/ — Maltese for “unique”
import { uuidv7 } from 'uniku/uuid/v7'

const id = uuidv7()
// => "018e5e5c-7c8a-7000-8000-000000000000"

// Time-ordered: IDs sort by creation time
const [first, second, third] = [uuidv7(), uuidv7(), uuidv7()]
console.log(first < second && second < third) // true

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

unikuuuidnanoidulidcuid2ksuid
UUID v4
UUID v7
ULID
CUID2
Nanoid
KSUID
Tree-shakeable
ESM-only✅¹
Edge/Workers⚠️⚠️
Byte ↔ String-⚠️²-
Notes:
  • ¹ uuid@13 is ESM-only; earlier versions support CommonJS.
  • ² ulid only 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:
Generatoruniku vs npm
ULID85× faster
CUID28× faster
KSUID1.5× faster
UUID v71.1× faster
Nanoid~comparable speed
UUID v4npm is 1.1× faster
For most use cases, uniku is either faster or comparable to dedicated single-format libraries.

Which ID Should I Use?

Choose the right ID format for your use case:
Use CaseRecommendedWhy
Database primary keysUUID v7 or ULIDTime-ordered for index efficiency
URL shortenersNanoidCompact, URL-safe characters
Prevent enumerationCUID2Non-sequential, secure
Maximum compatibilityUUID v4Universal standard
Distributed systemsULIDSortable + 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
UUID v4 (Maximum compatibility)
  • Purely random
  • 122 bits of entropy
  • Most widely supported
  • No time ordering
ULID (Alternative to UUID v7)
  • Time-ordered with millisecond precision
  • 128-bit (16 bytes)
  • Crockford Base32 encoded (URL-safe)
  • Lexicographically sortable
  • More compact string representation than UUID
CUID2 (Security-focused)
  • Non-sequential to prevent enumeration
  • Uses SHA3-512 hashing
  • Configurable length (2-32 characters)
  • No timestamp component
  • Best when you need unpredictability
Nanoid (Compact URLs)
  • 21 characters by default
  • URL-safe alphabet
  • Customizable size and alphabet
  • No time ordering
  • Smallest string representation
KSUID (Second-precision timestamp)
  • 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
uniku is ESM-only and does not support CommonJS. Make sure your project is configured for ESM.

Why Choose uniku?

  1. Modern Architecture: ESM-only, no legacy CommonJS support
  2. Universal Compatibility: Works in all JavaScript runtimes
  3. Truly Tree-Shakeable: Separate entry points, no barrel exports
  4. Byte-Level Control: Full binary serialization support
  5. Production Ready: Battle-tested with comprehensive test coverage
  6. 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

Build docs developers (and LLMs) love