[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-2928":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":22,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":19,"lastSyncTime":29,"discoverSource":30},2928,"nanoid","ai\u002Fnanoid","ai","A tiny (118 bytes), secure, URL-friendly, unique string ID generator for JavaScript","https:\u002F\u002Fzelark.github.io\u002Fnano-id-cc\u002F",null,"JavaScript",26822,851,155,3,0,13,53,2,43.79,"MIT License",false,"main",true,[],"2026-06-12 02:00:45","# Nano ID\n\n\u003Cimg src=\"https:\u002F\u002Fai.github.io\u002Fnanoid\u002Flogo.svg\" align=\"right\"\n     alt=\"Nano ID logo by Anton Lovchikov\" width=\"180\" height=\"94\">\n\n**English** | [日本語](.\u002FREADME.ja.md) | [Русский](.\u002FREADME.ru.md) | [简体中文](.\u002FREADME.zh-CN.md) | [Bahasa Indonesia](.\u002FREADME.id-ID.md) | [한국어](.\u002FREADME.ko.md) | [العربية](.\u002FREADME.ar.md)\n\nA tiny, secure, URL-friendly, unique string ID generator for JavaScript.\n\n> “An amazing level of senseless perfectionism,\n> which is simply impossible not to respect.”\n\n- **Small.** 118 bytes (minified and brotlied). No dependencies.\n  [Size Limit] controls the size.\n- **Safe.** It uses hardware random generator. Can be used in clusters.\n- **Short IDs.** It uses a larger alphabet than UUID (`A-Za-z0-9_-`).\n  So ID size was reduced from 36 to 21 symbols.\n- **Portable.** Nano ID was ported\n  to over [20 programming languages](.\u002FREADME.md#other-programming-languages).\n\n```js\nimport { nanoid } from 'nanoid'\nmodel.id = nanoid() \u002F\u002F=> \"V1StGXR8_Z5jdHi6B-myT\"\n```\n\n---\n\n\u003Cimg src=\"https:\u002F\u002Fcdn.evilmartians.com\u002Fbadges\u002Flogo-no-label.svg\" alt=\"\" width=\"22\" height=\"16\" \u002F>  Made at \u003Cb>\u003Ca href=\"https:\u002F\u002Fevilmartians.com\u002Fdevtools?utm_source=nanoid&utm_campaign=devtools-button&utm_medium=github\">Evil Martians\u003C\u002Fa>\u003C\u002Fb>, product consulting for \u003Cb>developer tools\u003C\u002Fb>.\n\n---\n\n[online tool]: https:\u002F\u002Fgitpod.io\u002F#https:\u002F\u002Fgithub.com\u002Fai\u002Fnanoid\u002F\n[with Babel]: https:\u002F\u002Fdeveloper.epages.com\u002Fblog\u002Fcoding\u002Fhow-to-transpile-node-modules-with-babel-and-webpack-in-a-monorepo\u002F\n[Size Limit]: https:\u002F\u002Fgithub.com\u002Fai\u002Fsize-limit\n\n## Table of Contents\n\n- [Table of Contents](#table-of-contents)\n- [Comparison with UUID](#comparison-with-uuid)\n- [Benchmark](#benchmark)\n- [Security](#security)\n- [Install](#install)\n  - [ESM](#esm)\n  - [CommonJS](#commonjs)\n  - [JSR](#jsr)\n  - [CDN](#cdn)\n- [API](#api)\n  - [Blocking](#blocking)\n  - [Non-Secure](#non-secure)\n  - [Custom Alphabet or Size](#custom-alphabet-or-size)\n  - [Custom Random Bytes Generator](#custom-random-bytes-generator)\n- [Usage](#usage)\n  - [React](#react)\n  - [React Native](#react-native)\n  - [PouchDB and CouchDB](#pouchdb-and-couchdb)\n  - [CLI](#cli)\n  - [TypeScript](#typescript)\n  - [Other Programming Languages](#other-programming-languages)\n- [Tools](#tools)\n\n## Comparison with UUID\n\nNano ID is quite comparable to UUID v4 (random-based).\nIt has a similar number of random bits in the ID\n(126 in Nano ID and 122 in UUID), so it has a similar collision probability:\n\n> For there to be a one in a billion chance of duplication,\n> 103 trillion version 4 IDs must be generated.\n\nThere are two main differences between Nano ID and UUID v4:\n\n1. Nano ID uses a bigger alphabet, so a similar number of random bits\n   are packed in just 21 symbols instead of 36.\n2. Nano ID code is **4 times smaller** than `uuid\u002Fv4` package:\n   118 bytes instead of 423.\n\n## Benchmark\n\n```rust\n$ node .\u002Ftest\u002Fbenchmark.js\ncrypto.randomUUID       21,741,317 ops\u002Fsec\nuuid v4                 21,204,378 ops\u002Fsec\n@napi-rs\u002Fuuid           10,236,615 ops\u002Fsec\nuid\u002Fsecure              10,567,676 ops\u002Fsec\n@lukeed\u002Fuuid             8,647,481 ops\u002Fsec\nnanoid                   7,800,308 ops\u002Fsec\ncustomAlphabet           9,697,350 ops\u002Fsec\nnanoid for browser         576,759 ops\u002Fsec\nsecure-random-string       529,253 ops\u002Fsec\nuid-safe.sync              526,459 ops\u002Fsec\n\nNon-secure:\nuid                     31,379,525 ops\u002Fsec\nnanoid\u002Fnon-secure        3,678,505 ops\u002Fsec\nrndm                     3,767,185 ops\u002Fsec\n```\n\nTest configuration: Framework 13 7840U, Fedora 39, Node.js 21.6.\n\n## Security\n\n_See a good article about random generators theory:\n[Secure random values (in Node.js)]_\n\n- **Unpredictability.** Instead of using the unsafe `Math.random()`, Nano ID\n  uses the `crypto` module in Node.js and the Web Crypto API in browsers.\n  These modules use unpredictable hardware random generator.\n- **Uniformity.** `random % alphabet` is a popular mistake to make when coding\n  an ID generator. The distribution will not be even; there will be a lower\n  chance for some symbols to appear compared to others. So, it will reduce\n  the number of tries when brute-forcing. Nano ID uses a [better algorithm]\n  and is tested for uniformity.\n\n  \u003Cimg src=\"img\u002Fdistribution.png\" alt=\"Nano ID uniformity\"\n     width=\"340\" height=\"135\">\n\n- **Well-documented:** all Nano ID hacks are documented. See comments\n  in [the source].\n- **Vulnerabilities:** to report a security vulnerability, please use\n  the [Tidelift security contact](https:\u002F\u002Ftidelift.com\u002Fsecurity).\n  Tidelift will coordinate the fix and disclosure.\n\n[Secure random values (in Node.js)]: https:\u002F\u002Fgist.github.com\u002Fjoepie91\u002F7105003c3b26e65efcea63f3db82dfba\n[better algorithm]: https:\u002F\u002Fgithub.com\u002Fai\u002Fnanoid\u002Fblob\u002Fmain\u002Findex.js\n[the source]: https:\u002F\u002Fgithub.com\u002Fai\u002Fnanoid\u002Fblob\u002Fmain\u002Findex.js\n\n## Install\n\n### ESM\n\nNano ID 5 works with ESM projects (with `import`) in tests or Node.js scripts.\n\n```bash\nnpm install nanoid\n```\n\n### CommonJS\n\nNano ID can be used with CommonJS in one of the following ways:\n\n- You can use `require()` to import Nano ID. You need to use latest Node.js\n  22.12 (works out-of-the-box) or Node.js 20\n  (with `--experimental-require-module`).\n\n- For Node.js 18 you can dynamically import Nano ID as follows:\n\n  ```js\n  let nanoid\n  module.exports.createID = async () => {\n    if (!nanoid) ({ nanoid } = await import('nanoid'))\n    return nanoid() \u002F\u002F => \"V1StGXR8_Z5jdHi6B-myT\"\n  }\n  ```\n\n- You can use Nano ID 3.x (we still support it):\n\n  ```bash\n  npm install nanoid@3\n  ```\n\n### JSR\n\n[JSR](https:\u002F\u002Fjsr.io) is a replacement for npm with open governance\nand active development (in contrast to npm).\n\n```bash\nnpx jsr add @sitnik\u002Fnanoid\n```\n\nYou can use it in Node.js, Deno, Bun, etc.\n\n```js\n\u002F\u002F Replace `nanoid` to `@sitnik\u002Fnanoid` in all imports\nimport { nanoid } from '@sitnik\u002Fnanoid'\n```\n\nFor Deno install it by `deno add jsr:@sitnik\u002Fnanoid` or import\nfrom `jsr:@sitnik\u002Fnanoid`.\n\n### CDN\n\nFor quick hacks, you can load Nano ID from CDN. Though, it is not recommended\nto be used in production because of the lower loading performance.\n\n```js\nimport { nanoid } from 'https:\u002F\u002Fcdn.jsdelivr.net\u002Fnpm\u002Fnanoid\u002Fnanoid.js'\n```\n\n## API\n\nNano ID has 2 APIs: normal and non-secure.\n\nBy default, Nano ID uses URL-friendly symbols (`A-Za-z0-9_-`) and returns an ID\nwith 21 characters (to have a collision probability similar to UUID v4).\n\n### Blocking\n\nThe safe and easiest way to use Nano ID.\n\nIn rare cases could block CPU from other work while noise collection\nfor hardware random generator.\n\n```js\nimport { nanoid } from 'nanoid'\nmodel.id = nanoid() \u002F\u002F=> \"V1StGXR8_Z5jdHi6B-myT\"\n```\n\nIf you want to reduce the ID size (and increase collisions probability),\nyou can pass the size as an argument.\n\n```js\nnanoid(10) \u002F\u002F=> \"IRFa-VaY2b\"\n```\n\nDon’t forget to check the safety of your ID size\nin our [ID collision probability] calculator.\n\nYou can also use a [custom alphabet](#custom-alphabet-or-size)\nor a [random generator](#custom-random-bytes-generator).\n\n[ID collision probability]: https:\u002F\u002Fzelark.github.io\u002Fnano-id-cc\u002F\n\n### Non-Secure\n\nBy default, Nano ID uses hardware random bytes generation for security\nand low collision probability. If you are not so concerned with security,\nyou can use it for environments without hardware random generators.\n\n```js\nimport { nanoid } from 'nanoid\u002Fnon-secure'\nconst id = nanoid() \u002F\u002F=> \"Uakgb_J5m9g-0JDMbcJqLJ\"\n```\n\n### Custom Alphabet or Size\n\n`customAlphabet` returns a function that allows you to create `nanoid`\nwith your own alphabet and ID size.\n\n```js\nimport { customAlphabet } from 'nanoid'\nconst nanoid = customAlphabet('1234567890abcdef', 10)\nmodel.id = nanoid() \u002F\u002F=> \"4f90d13a42\"\n```\n\n```js\nimport { customAlphabet } from 'nanoid\u002Fnon-secure'\nconst nanoid = customAlphabet('1234567890abcdef', 10)\nuser.id = nanoid()\n```\n\nCheck the safety of your custom alphabet and ID size in our\n[ID collision probability] calculator. For more alphabets, check out the options\nin [`nanoid-dictionary`].\n\nAlphabet must contain 256 symbols or less.\nOtherwise, the security of the internal generator algorithm is not guaranteed.\n\nIn addition to setting a default size, you can change the ID size when calling\nthe function:\n\n```js\nimport { customAlphabet } from 'nanoid'\nconst nanoid = customAlphabet('1234567890abcdef', 10)\nmodel.id = nanoid(5) \u002F\u002F=> \"f01a2\"\n```\n\n[`nanoid-dictionary`]: https:\u002F\u002Fgithub.com\u002FCyberAP\u002Fnanoid-dictionary\n\n### Custom Random Bytes Generator\n\n`customRandom` allows you to create a `nanoid` and replace alphabet\nand the default random bytes generator.\n\nIn this example, a seed-based generator is used:\n\n```js\nimport { customRandom } from 'nanoid'\n\nconst rng = seedrandom(seed)\nconst nanoid = customRandom('abcdef', 10, size => {\n  return new Uint8Array(size).map(() => 256 * rng())\n})\n\nnanoid() \u002F\u002F=> \"fbaefaadeb\"\n```\n\n`random` callback must accept the array size and return an array\nwith random numbers.\n\nIf you want to use the same URL-friendly symbols with `customRandom`,\nyou can get the default alphabet using the `urlAlphabet`.\n\n```js\nimport { customRandom, urlAlphabet } from 'nanoid'\nconst nanoid = customRandom(urlAlphabet, 10, random)\n```\n\nNote, that between Nano ID versions we may change random generator\ncall sequence. If you are using seed-based generators, we do not guarantee\nthe same result.\n\n## Usage\n\n### React\n\nThere’s no correct way to use Nano ID for React `key` prop\nsince it should be consistent among renders.\n\n```jsx\nfunction Todos({ todos }) {\n  return (\n    \u003Cul>\n      {todos.map(todo => (\n        \u003Cli key={nanoid()}>\n          {' '}\n          \u002F* DON’T DO IT *\u002F\n          {todo.text}\n        \u003C\u002Fli>\n      ))}\n    \u003C\u002Ful>\n  )\n}\n```\n\nYou should rather try to reach for stable ID inside your list item.\n\n```jsx\nconst todoItems = todos.map(todo => \u003Cli key={todo.id}>{todo.text}\u003C\u002Fli>)\n```\n\nIn case you don’t have stable IDs you'd rather use index as `key`\ninstead of `nanoid()`:\n\n```jsx\nconst todoItems = todos.map((text, index) => (\n  \u003Cli key={index}>\n    {' '}\n    \u002F* Still not recommended but preferred over nanoid(). Only do this if items\n    have no stable IDs. *\u002F\n    {text}\n  \u003C\u002Fli>\n))\n```\n\nIn case you just need random IDs to link elements like labels\nand input fields together, [`useId`] is recommended.\nThat hook was added in React 18.\n\n[`useId`]: https:\u002F\u002Freact.dev\u002Freference\u002Freact\u002FuseId\n\n### React Native\n\nReact Native does not have built-in random generator. The following polyfill\nworks for plain React Native and Expo starting with `39.x`.\n\n1. Check [`react-native-get-random-values`] docs and install it.\n2. Import it before Nano ID.\n\n```js\nimport 'react-native-get-random-values'\nimport { nanoid } from 'nanoid'\n```\n\n[`react-native-get-random-values`]: https:\u002F\u002Fgithub.com\u002FLinusU\u002Freact-native-get-random-values\n\n### PouchDB and CouchDB\n\nIn PouchDB and CouchDB, IDs can’t start with an underscore `_`.\nA prefix is required to prevent this issue, as Nano ID might use a `_`\nat the start of the ID by default.\n\nOverride the default ID with the following option:\n\n```js\ndb.put({\n  _id: 'id' + nanoid(),\n  …\n})\n```\n\n### CLI\n\nYou can get unique ID in terminal by calling `npx nanoid`. You need only\nNode.js in the system. You do not need Nano ID to be installed anywhere.\n\n```sh\n$ npx nanoid\nnpx: installed 1 in 0.63s\nLZfXLFzPPR4NNrgjlWDxn\n```\n\nSize of generated ID can be specified with `--size` (or `-s`) option:\n\n```sh\n$ npx nanoid --size 10\nL3til0JS4z\n```\n\nCustom alphabet can be specified with `--alphabet` (or `-a`) option\n(note that in this case `--size` is required):\n\n```sh\n$ npx nanoid --alphabet abc --size 15\nbccbcabaabaccab\n```\n\n### TypeScript\n\nNano ID allows casting generated strings into opaque strings in TypeScript.\nFor example:\n\n```ts\ndeclare const userIdBrand: unique symbol\ntype UserId = string & { [userIdBrand]: true }\n\n\u002F\u002F Use explicit type parameter:\nmockUser(nanoid\u003CUserId>())\n\ninterface User {\n  id: UserId\n  name: string\n}\n\nconst user: User = {\n  \u002F\u002F Automatically casts to UserId:\n  id: nanoid(),\n  name: 'Alice'\n}\n```\n\n### Other Programming Languages\n\nNano ID was ported to many languages. You can use these ports to have\nthe same ID generator on the client and server side.\n\n- [C](https:\u002F\u002Fgithub.com\u002Flukateras\u002Fnanoid.h)\n- [C#](https:\u002F\u002Fgithub.com\u002Fcodeyu\u002Fnanoid-net)\n- [C++](https:\u002F\u002Fgithub.com\u002Fmcmikecreations\u002Fnanoid_cpp)\n- [Clojure and ClojureScript](https:\u002F\u002Fgithub.com\u002Fzelark\u002Fnano-id)\n- [ColdFusion\u002FCFML](https:\u002F\u002Fgithub.com\u002FJamoCA\u002Fcfml-nanoid)\n- [Crystal](https:\u002F\u002Fgithub.com\u002Fmamantoha\u002Fnanoid.cr)\n- [Dart & Flutter](https:\u002F\u002Fgithub.com\u002Fpd4d10\u002Fnanoid-dart)\n- [Elixir](https:\u002F\u002Fgithub.com\u002Frailsmechanic\u002Fnanoid)\n- [Gleam](https:\u002F\u002Fgithub.com\u002F0xca551e\u002Fglanoid)\n- [Go](https:\u002F\u002Fgithub.com\u002Fmatoous\u002Fgo-nanoid)\n- [Haskell](https:\u002F\u002Fgithub.com\u002FMichelBoucey\u002FNanoID)\n- [Haxe](https:\u002F\u002Fgithub.com\u002Fflashultra\u002Fuuid)\n- [Janet](https:\u002F\u002Fsr.ht\u002F~statianzo\u002Fjanet-nanoid\u002F)\n- [Java](https:\u002F\u002Fgithub.com\u002Fwosherco\u002Fjnanoid-enhanced)\n- [Kotlin](https:\u002F\u002Fgithub.com\u002Fviascom\u002Fnanoid-kotlin)\n- [MySQL\u002FMariaDB](https:\u002F\u002Fgithub.com\u002Fviascom\u002Fnanoid-mysql-mariadb)\n- [Nim](https:\u002F\u002Fgithub.com\u002Ficyphox\u002Fnanoid.nim)\n- [OCaml](https:\u002F\u002Fgithub.com\u002Froutineco\u002Focaml-nanoid)\n- [Perl](https:\u002F\u002Fgithub.com\u002Ftkzwtks\u002FNanoid-perl)\n- [PHP](https:\u002F\u002Fgithub.com\u002Fhidehalo\u002Fnanoid-php)\n- Python [native](https:\u002F\u002Fgithub.com\u002Fpuyuan\u002Fpy-nanoid) implementation\n  with [dictionaries](https:\u002F\u002Fpypi.org\u002Fproject\u002Fnanoid-dictionary)\n  and [fast](https:\u002F\u002Fgithub.com\u002Foliverlambson\u002Ffastnanoid) implementation (written in Rust)\n- Postgres [Extension](https:\u002F\u002Fgithub.com\u002Fspa5k\u002Fuids-postgres)\n  and [Native Function](https:\u002F\u002Fgithub.com\u002Fviascom\u002Fnanoid-postgres)\n- [R](https:\u002F\u002Fgithub.com\u002Fhrbrmstr\u002Fnanoid) (with dictionaries)\n- [Ruby](https:\u002F\u002Fgithub.com\u002Fradeno\u002Fnanoid.rb)\n- [Rust](https:\u002F\u002Fgithub.com\u002Fnikolay-govorov\u002Fnanoid)\n- [Swift](https:\u002F\u002Fgithub.com\u002FShivaHuang\u002Fswift-nanoid)\n- [Unison](https:\u002F\u002Fshare.unison-lang.org\u002Flatest\u002Fnamespaces\u002Fhojberg\u002Fnanoid)\n- [V](https:\u002F\u002Fgithub.com\u002Finvipal\u002Fnanoid)\n- [Zig](https:\u002F\u002Fgithub.com\u002FSasLuca\u002Fzig-nanoid)\n\nFor other environments, [CLI] is available to generate IDs from a command line.\n\n[CLI]: #cli\n\n## Tools\n\n- [ID size calculator] shows collision probability when adjusting\n  the ID alphabet or size.\n- [`nanoid-dictionary`] with popular alphabets to use with [`customAlphabet`].\n- [`nanoid-good`] to be sure that your ID doesn’t contain any obscene words.\n\n[`nanoid-dictionary`]: https:\u002F\u002Fgithub.com\u002FCyberAP\u002Fnanoid-dictionary\n[ID size calculator]: https:\u002F\u002Fzelark.github.io\u002Fnano-id-cc\u002F\n[`customAlphabet`]: #custom-alphabet-or-size\n[`nanoid-good`]: https:\u002F\u002Fgithub.com\u002Fy-gagar1n\u002Fnanoid-good\n","Nano ID 是一个用于JavaScript的微型、安全、URL友好的唯一字符串ID生成器。其核心功能包括使用硬件随机数生成器确保安全性，支持集群环境下的使用；通过采用更大的字符集（A-Za-z0-9_-），将ID长度从UUID的36个字符缩短至21个字符，同时保持了与UUID v4相似的碰撞概率。此外，Nano ID体积极小，压缩后仅118字节，并且无任何依赖项。该项目适用于需要快速生成短小、安全且全球唯一标识符的各种Web应用或服务场景中，如数据库记录ID、会话令牌等。","2026-06-11 02:51:44","top_language"]