NanoId#
A Kotlin Multiplatform port of this JavaScript library, providing a fast, secure and URL-friendly unique ID generator.
🎯 Supported Targets#
The following targets are supported:
| Platform | Targets |
|---|---|
| JVM & Android | jvm, android |
| Apple | ios, macos, tvos, watchos |
| Web | js, wasmJs |
| Native & Other | linux, mingw |
✨ Features#
NanoId comes with several features while beeing fully customizable.
🔒 Secure#
NanoId uses Korlibs Crypto SecureRandom to generate cryptographically strong random IDs with a proper distribution of characters.
Crypto provides a SecureRandom class that extends the kotlin.random.Random class, but generating cryptographic secure values.
- It uses
SecureRandomon the JVM +PRNGFixeson Android. - On Native POSIX (including Linux, macOS, iOS) it uses
/dev/urandom - On Windows
BCryptGenRandomis in use
📦 Compact#
NanoId generates compact IDs with just 21 characters.
By using a larger alphabet than UUID, NanoId can generate a greater number of unique IDs, when compared to UUID, with fewer characters (21 vs 36).
🖌️ Customizable#
NanoId is fully customizable.
All default options may be overridden. Supply your own Random Number Generator, alphabet or size.
🚀 Installation#
Integration using Version Catalog is highly recommended for aligned version usage.
🛠️ Usage#
Creating a default URL-friendly unique identifier:
Customizing the generated output:
val generator = Random()
val alphabet = "0123456789"
val size = 20
val id = NanoId.generate(generator, alphabet, size)