跳到主要内容
uencoder

生成 NanoIDs for compact unique identifiers

NanoID 是微小, URL-safe, 唯一 ID generator. Smaller 和 faster than UUID, 具有 customizable alphabet 和大小.

  1. 1

    NanoID 是 21-字符 URL-safe ID (默认 alphabet: A-Za-z0-9_-). 它是 4 bytes shorter than UUID v4 (36 chars 具有 hyphens) 和 faster 到生成. collision 概率是 negligible: 具有 21 chars 从 64-char alphabet, 你 need 2^63 IDs 为 50% collision chance. NanoID 是 ideal 为 URLs, 数据库关键, 和组件 IDs.

  2. 2
    UUID / ULID 生成器 →

    生成 a UUID for comparison. UUID v4 is 36 characters (32 hex + 4 hyphens). NanoID is 21 characters — 40% shorter. For URL-safe IDs, NanoID is preferable (UUID uses hyphens which may need encoding in some contexts). Use UUID when you need RFC 4122 compliance; use NanoID for compact, URL-safe IDs.

  3. 3
    Base58 编码器 →

    为 even shorter IDs, 编码 random 数字在 Base58 (Bitcoin alphabet, 否 0/O/I/l). 16-字节 random 数字在 Base58 是 ~22 characters. Base58 是 URL-safe 和 human-readable (否 ambiguous characters). Use 此为 用户-facing IDs where 长度 matters.

  4. 4
    随机字节生成器 →

    生成 the random bytes for NanoID. NanoID uses a CSPRNG (crypto.getRandomValues) for security. 21 characters from a 64-character alphabet provides 126 bits of entropy — sufficient for global uniqueness with negligible collision probability.

常见问题

NanoID vs UUID — 哪个到 use?
Use NanoID 为 compact, URL-safe IDs (URLs, 数据库关键, 组件 IDs). Use UUID 当你 need RFC 4122 合规, 标准格式化 (8-4-4-4-12), 或 interoperability 具有 systems 该 expect UUIDs. NanoID 是 shorter (21 vs 36 chars) 和 faster, 但 UUID 是更多宽 recognized.
能够 I customize NanoID?
是. Specify 大小 (默认 21) 和 alphabet (默认 URL-safe: _-0-9a-zA-Z). 为 larger alphabet (更多 entropy per char), use Base64. 为 human-readable IDs, use 自定义 alphabet 无 ambiguous characters (0/O, 1/l/I). 为 prefixed IDs (user_xxx), prepend prefix 到 generated ID.

解决此任务的工作流

相关工具