Overview of Nano ID
mainNano ID is a lightweight, secure, and fast unique ID generator for JavaScript. It is designed to be URL-friendly and can be used in various environments including modern browsers, Node.js, React Native, and even older IE (via Babel).
Key features:
- Lightweight: ~118 bytes (minified + Brotli) with zero dependencies.
- Fast: Significantly faster than native
crypto.randomUUID(). - Secure: Uses hardware-based random number generators (Web Crypto API in browsers,
cryptomodule in Node.js). - Compact: Uses a larger alphabet (
A-Za-z0-9_-) than UUID, allowing for a shorter ID length (21 characters) while maintaining similar collision resistance (126 bits of randomness vs 122 bits in UUID).
import { nanoid } from 'nanoid'
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"