@omerdev/safe-id
v1.0.0
Published
Cryptographically secure, nano-fast, collision-resistant unique ID & OTP generator with zero dependencies (<1KB)
Maintainers
Readme
🔑 @omerdev/safe-id
Cryptographically secure, nano-fast, collision-resistant unique ID & OTP generator with zero dependencies (<1KB).
⚡ Why safe-id?
- Cryptographically Secure: Uses
crypto.getRandomValues()/crypto.randomBytes. - Zero Dependencies: Less than 1KB bundled size.
- Stripe-Style Prefixes: Easily generate IDs like
usr_a9Z2kx...orinv_98jL2.... - Built-in OTP Generator: Generate 6-digit or N-digit numeric codes with guaranteed uniform randomness.
- Universal: Works seamlessly in Node.js, Bun, Deno, browsers, Cloudflare Workers.
📦 Installation
npm install @omerdev/safe-id
# or
pnpm add @omerdev/safe-id
# or
bun add @omerdev/safe-id💡 Quick Start
import { safeId, shortId, prefixedId, numericOtp } from "@omerdev/safe-id";
// 1. Standard URL-safe ID (21 characters)
const id = safeId();
// "V1StGXR8_Z5jdHi6B-myT"
// 2. Short link ID (8 characters)
const short = shortId();
// "k8Fa2Lp0"
// 3. Stripe-style entity ID
const userId = prefixedId("usr");
// "usr_9kL2x0ZaP41mQ8vZ"
const orderId = prefixedId("ord", 20);
// "ord_81JkLa09ZmcP5412QxLz"
// 4. Numeric OTP code
const code = numericOtp(6);
// "842915"👤 Author
omerdev
📄 License
MIT
