@knownasrazi/nanoid
v1.0.0
Published
Tiny secure random ID generator with custom alphabet and output size.
Maintainers
Readme
nanoid
Tiny secure random ID generator.
Zero dependencies - ~2 KB gzipped - TypeScript - Node + Bun + browser
Install
bun add @knownasrazi/nanoid
npm install @knownasrazi/nanoidUsage
import { nanoid, customAlphabet } from "@knownasrazi/nanoid";
nanoid(); // "4Kf9w..."
nanoid("0123456789", 6); // "483920"
nanoid("abcdef", 10); // only a-f
const next = customAlphabet("0123456789", 6);
next(); // "392018"API
| Export | Signature |
| --- | --- |
| nanoid(alphabet?, size?) | (string=alnum, number=21) => string |
| customAlphabet(alphabet, size) | () => string bound generator |
Uses crypto.getRandomValues. Throws RangeError on empty alphabet / bad size.
Development
git clone https://github.com/knownasrazi/nanoid.git
cd nanoid
bun install
bun test
bun run build
bun run lintLicense
nanoid - ids in a blink.
