Smart IDs combine a domain prefix (e.g. usr, inv, sub, tok) with high-entropy randomized strings, popularized by companies like Stripe and GitHub. They significantly enhance observability in API logs, stack traces, and database debugging.
Usage and Options
js
import { smart } from '@readytools/id';
// Default: NanoID entropy with underscore separator
const userId = smart('usr');
// Returns: "usr_V1StGXR8_Z5jdHi6B-myT"
// Compact UUIDv7 entropy for database primary keys
const orderId = smart('ord', { type: 'uuidv7' });
// Returns: "ord_018f6f898d2a71409a3b586b9e248b11"
// CUID2 entropy
const accountId = smart('acc', { type: 'cuid2' });
// Returns: "acc_tz4a98xxat96iws9zmbrgj3a"
// Date-partitioned prefix (YYYYMMDD) for S3 keys or daily logs
const logId = smart('log', { date: true });
// Returns: "log_20260823_V1StGXR8_Z5jdHi6B-myT"
// Custom delimiter
const sessionKey = smart('sess', { separator: '-' });
// Returns: "sess-V1StGXR8_Z5jdHi6B-myT"⚡ Live Playground
smart()
Generating...
📏 Calculating...✨ Web Crypto Native
Configuration Interface
ts
interface SmartOptions {
type?: 'nano' | 'uuidv7' | 'cuid2'; // Generator algorithm (default: 'nano')
date?: boolean; // Prepend UTC date YYYYMMDD (default: false)
separator?: string; // Delimiter character (default: '_')
}