idchunk
v2.4.0
Published
Tiny, Fast & Customizable ID Generator
Maintainers
Readme
⚡ idchunk — Tiny, Blazingly Fast & Customizable ID Generator
Generate short, secure, and customizable IDs for your applications in milliseconds.
✨ Features
- 🚀 Blazingly Fast: Uses optimized bulk random-byte generation for maximum performance.
- 🛡️ TypeScript Ready: Native
.d.tsdefinitions included out of the box. - 🧩 Built-in Presets: Instantly generate OTP numbers, hex tokens, and more.
- 📦 Tiny: Zero dependencies, incredibly minimal footprint.
- 🔒 Secure: Uses Node.js
cryptofor cryptographically secure randomness. - 🛠️ Customizable: Choose the exact length and your own custom character set.
🏎️ Benchmark
Recorded on June 21, 2026 (1,000,000 iterations generating 10-character IDs).
idchunk is ~40% faster than NanoID when using custom alphabets!
| Library | Standard (10 chars) | Custom Alphabet (10 chars) |
| :--- | :--- | :--- |
| crypto.randomUUID() | 101.69 ms | N/A |
| uuid v4 | 184.39 ms | N/A |
| nanoid | 211.22 ms | 472.50 ms |
| idchunk | 235.55 ms | 288.59 ms 🏆 |
📦 Installation
npm install idchunkUsage
By default, idchunk() generates a random ID of length 10:
const idchunk = require("idchunk");
console.log(idchunk());
// Example: "aZ8_-kL2pQ"You can specify a custom length:
console.log(idchunk(16));
// Example: "bQ9pL2_-aZ8kL2pQ"Custom character set:
const customValues = "ABC123";
console.log(idchunk(8, customValues));
// Example: "1A23BCAB"🎯 Built-in Presets
Don't want to define custom alphabets? Use the built-in presets:
const idchunk = require("idchunk");
console.log(idchunk.numbers(6)); // "829103" - Great for OTPs and 2FA
console.log(idchunk.hex(12)); // "e4368746a829" - Great for tokens
console.log(idchunk.lowercase(8)); // "ymddmahe"
console.log(idchunk.uppercase(8)); // "WFKVFGSW"API
idchunk(length?: number, customValues?: string): string
length(optional) → Length of the ID (default: 10).customValues(optional) → String of allowed characters (default: a-zA-Z0-9_-).- Returns: Random string ID.
idchunk.numbers(length?: number): string
idchunk.hex(length?: number): string
idchunk.lowercase(length?: number): string
idchunk.uppercase(length?: number): string
How It Works
- Pre-allocates an array of secure random bytes using Node.js
crypto.randomBytesorcrypto.getRandomValues()for a massive performance boost over single-character generation. - Default character set:
a-z,A-Z,0-9,_,-.
📄 License
MIT © Garv Thakral
Documentation
Read full documentation here : Read Docs
