{"_id":"crypto-random-string","_rev":"4129118","name":"crypto-random-string","description":"Generate a cryptographically strong random string","dist-tags":{"latest":"5.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-03-01T18:29:25.000Z","created":"2016-11-14T04:14:44.263Z","5.0.0":"2022-05-10T06:15:36.108Z","4.0.0":"2021-04-05T08:12:23.306Z","3.3.1":"2021-02-12T10:16:47.305Z","3.3.0":"2020-09-03T13:20:46.016Z","3.2.0":"2020-03-07T05:51:44.758Z","3.1.0":"2020-01-12T07:23:54.762Z","3.0.1":"2019-06-17T09:12:26.665Z","3.0.0":"2019-05-08T13:01:11.451Z","2.0.0":"2019-04-09T19:49:44.165Z","1.0.0":"2016-11-14T04:14:44.263Z"},"users":{"rocket0191":true,"heartnett":true,"jon_shen":true,"ackhub":true,"shivayl":true,"td3":true,"hualei":true},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"versions":{"5.0.0":{"name":"crypto-random-string","version":"5.0.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","node":"./index.js","browser":"./browser.js"},"engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","pin","crypto","strong","secure","hex","secret","protect"],"dependencies":{"type-fest":"^2.12.2"},"devDependencies":{"ava":"^4.2.0","dot-prop":"^7.2.0","tsd":"^0.20.0","xo":"^0.48.0"},"types":"./index.d.ts","gitHead":"25f8930282bc3803d03b9080e710db8426430b63","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@5.0.0","_nodeVersion":"16.15.0","_npmVersion":"8.3.2","dist":{"shasum":"12b4ca8ba936c36d757b65b71a7d85a69a02c18a","size":5294,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-5.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-5.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_5.0.0_1652163335875_0.7548451044247599"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-05-10T06:23:07.781Z","publish_time":1652163336108,"_cnpm_publish_time":1652163336108},"4.0.0":{"name":"crypto-random-string","version":"4.0.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","pin","crypto","strong","secure","hex","secret","protect"],"dependencies":{"type-fest":"^1.0.1"},"devDependencies":{"ava":"^3.15.0","tsd":"^0.14.0","xo":"^0.38.2"},"gitHead":"a93cea08c5a1edfce2e2888651987686d03a57ba","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@4.0.0","_nodeVersion":"12.20.1","_npmVersion":"6.14.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"5a3cc53d7dd86183df5da0312816ceeeb5bb1fc2","size":4628,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-4.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-4.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_4.0.0_1617610343127_0.64990720946612"},"_hasShrinkwrap":false,"publish_time":1617610343306,"_cnpm_publish_time":1617610343306},"3.3.1":{"name":"crypto-random-string","version":"3.3.1","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","pin","crypto","strong","secure","hex","secret","protect"],"dependencies":{"type-fest":"^0.8.1"},"devDependencies":{"ava":"^2.1.0","tsd":"^0.11.0","xo":"^0.25.3"},"gitHead":"d78436d6d0b36029d0f54d3b6cabadc3f3872755","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@3.3.1","_nodeVersion":"10.22.1","_npmVersion":"6.14.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"13cee94cac8001e4842501608ef779e0ed08f82d","size":4328,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-3.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-3.3.1.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_3.3.1_1613125007162_0.845884375786154"},"_hasShrinkwrap":false,"publish_time":1613125007305,"_cnpm_publish_time":1613125007305},"3.3.0":{"name":"crypto-random-string","version":"3.3.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","pin","crypto","strong","secure","hex","secret","protect"],"dependencies":{"type-fest":"^0.8.1"},"devDependencies":{"ava":"^2.1.0","tsd":"^0.11.0","xo":"^0.25.3"},"gitHead":"98e54d259454598b753b88b3096321c308de66fb","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@3.3.0","_nodeVersion":"10.22.0","_npmVersion":"6.14.7","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"c7a4682b2a87146a1f8b7378ea2606f95775e7e6","size":4372,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-3.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-3.3.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_3.3.0_1599139245807_0.701439802088156"},"_hasShrinkwrap":false,"publish_time":1599139246016,"_cnpm_publish_time":1599139246016},"3.2.0":{"name":"crypto-random-string","version":"3.2.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","pin","crypto","strong","secure","hex","secret","protect"],"dependencies":{"type-fest":"^0.8.1"},"devDependencies":{"ava":"^2.1.0","tsd":"^0.11.0","xo":"^0.25.3"},"gitHead":"9b3a4704ab94a94f48197c4eb9c7409829b279a3","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@3.2.0","_nodeVersion":"10.18.1","_npmVersion":"6.14.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"d513ef0c2ac6ff7cad5769de585d9bf2ad5a2b4d","size":3771,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-3.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-3.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_3.2.0_1583560304604_0.14857320893519166"},"_hasShrinkwrap":false,"publish_time":1583560304758,"_cnpm_publish_time":1583560304758},"3.1.0":{"name":"crypto-random-string","version":"3.1.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","pin","crypto","strong","secure","hex","secret","protect"],"dependencies":{"type-fest":"^0.8.1"},"devDependencies":{"ava":"^2.1.0","tsd":"^0.11.0","xo":"^0.25.3"},"gitHead":"9f4539975027bf6e8f2478b5ed7ed47562a65522","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@3.1.0","_nodeVersion":"10.17.0","_npmVersion":"6.11.3","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"0368382de82e914179ad2ca9c7a788e260184bae","size":3512,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-3.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-3.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_3.1.0_1578813834652_0.18457452885833714"},"_hasShrinkwrap":false,"publish_time":1578813834762,"_cnpm_publish_time":1578813834762},"3.0.1":{"name":"crypto-random-string","version":"3.0.1","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","crypto","strong","secure","hex"],"dependencies":{"type-fest":"^0.5.2"},"devDependencies":{"ava":"^2.1.0","tsd":"^0.7.3","xo":"^0.24.0"},"gitHead":"bf79cb61af7ca36a61d92247e1ac5d76f9f57664","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@3.0.1","_nodeVersion":"8.16.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"29d7dc759d577a768afb3b7b2765dd9bd7ffe36a","size":3234,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-3.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-3.0.1.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_3.0.1_1560762746558_0.06229205104022184"},"_hasShrinkwrap":false,"publish_time":1560762746665,"_cnpm_publish_time":1560762746665},"3.0.0":{"name":"crypto-random-string","version":"3.0.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","crypto","strong","secure","hex"],"dependencies":{"type-fest":"^0.4.1"},"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"32365366245e602a58a2a38c4d6fc2edd30355d7","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@3.0.0","_nodeVersion":"8.16.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"b173d4228bf42a6cd38447129f579133438c50d4","size":3212,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-3.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_3.0.0_1557320471343_0.2992947319068162"},"_hasShrinkwrap":false,"publish_time":1557320471451,"_cnpm_publish_time":1557320471451},"2.0.0":{"name":"crypto-random-string","version":"2.0.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["random","string","text","id","identifier","slug","salt","crypto","strong","secure","hex"],"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"02bce8d99d653abb3271890569f923592ae7d756","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"ef2a7a966ec11083388369baa02ebead229b30d5","size":1902,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-2.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-random-string_2.0.0_1554839383983_0.9523177438892618"},"_hasShrinkwrap":false,"publish_time":1554839384165,"_cnpm_publish_time":1554839384165},"1.0.0":{"name":"crypto-random-string","version":"1.0.0","description":"Generate a cryptographically strong random string","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/crypto-random-string.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["random","string","str","rand","text","id","identifier","slug","salt","crypto","strong","secure","hex"],"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"21960c996c3f77cf5f7bf6765e837e7c8a07e200","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","_id":"crypto-random-string@1.0.0","_shasum":"a230f64f568310e1498009940790ec99545bca7e","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.6.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"a230f64f568310e1498009940790ec99545bca7e","size":1818,"noattachment":false,"key":"/crypto-random-string/-/crypto-random-string-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/crypto-random-string/download/crypto-random-string-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/crypto-random-string-1.0.0.tgz_1479096882597_0.12821740517392755"},"directories":{},"publish_time":1479096884263,"_cnpm_publish_time":1479096884263,"_hasShrinkwrap":false}},"readme":"# crypto-random-string\n\n> Generate a [cryptographically strong](https://en.wikipedia.org/wiki/Strong_cryptography) random string\n\nCan be useful for creating an identifier, slug, salt, PIN code, fixture, etc.\n\nWorks in Node.js and browsers.\n\n## Install\n\n```sh\nnpm install crypto-random-string\n```\n\n## Usage\n\n```js\nimport cryptoRandomString from 'crypto-random-string';\n\ncryptoRandomString({length: 10});\n//=> '2cf05d94db'\n\ncryptoRandomString({length: 10, type: 'base64'});\n//=> 'YMiMbaQl6I'\n\ncryptoRandomString({length: 10, type: 'url-safe'});\n//=> 'YN-tqc8pOw'\n\ncryptoRandomString({length: 10, type: 'numeric'});\n//=> '8314659141'\n\ncryptoRandomString({length: 6, type: 'distinguishable'});\n//=> 'CDEHKM'\n\ncryptoRandomString({length: 10, type: 'ascii-printable'});\n//=> '`#Rt8$IK>B'\n\ncryptoRandomString({length: 10, type: 'alphanumeric'});\n//=> 'DMuKL8YtE7'\n\ncryptoRandomString({length: 10, characters: 'abc'});\n//=> 'abaaccabac'\n```\n\n## API\n\n### cryptoRandomString(options)\n\nReturns a randomized string. [Hex](https://en.wikipedia.org/wiki/Hexadecimal) by default.\n\n### cryptoRandomStringAsync(options)\n\nReturns a promise which resolves to a randomized string. [Hex](https://en.wikipedia.org/wiki/Hexadecimal) by default.\n\nFor most use-cases, there's really no good reason to use this async version. From the Node.js docs:\n\n> The `crypto.randomBytes()` method will not complete until there is sufficient entropy available. This should normally never take longer than a few milliseconds. The only time when generating the random bytes may conceivably block for a longer period of time is right after boot, when the whole system is still low on entropy.\n\nIn general, anything async comes with some overhead on it's own.\n\n```js\nimport {cryptoRandomStringAsync} from 'crypto-random-string';\n\nawait cryptoRandomStringAsync({length: 10});\n//=> '2cf05d94db'\n```\n\n#### options\n\nType: `object`\n\n##### length\n\n*Required*\\\nType: `number`\n\nLength of the returned string.\n\n##### type\n\nType: `string`\\\nDefault: `'hex'`\\\nValues: `'hex' | 'base64' | 'url-safe' | 'numeric' | 'distinguishable' | 'ascii-printable' | 'alphanumeric'`\n\nUse only characters from a predefined set of allowed characters.\n\nCannot be set at the same time as the `characters` option.\n\nThe `distinguishable` set contains only uppercase characters that are not easily confused: `CDEHKMPRTUWXY012458`. It can be useful if you need to print out a short string that you'd like users to read and type back in with minimal errors. For example, reading a code off of a screen that needs to be typed into a phone to connect two devices.\n\nThe `ascii-printable` set contains all [printable ASCII characters](https://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters): ``!\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~`` Useful for generating passwords where all possible ASCII characters should be used.\n\nThe `alphanumeric` set contains uppercase letters, lowercase letters, and digits: `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`. Useful for generating [nonce](https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/nonce) values.\n\n##### characters\n\nType: `string`\\\nMinimum length: `1`\\\nMaximum length: `65536`\n\nUse only characters from a custom set of allowed characters.\n\nCannot be set at the same time as the `type` option.\n\n## Related\n\n- [random-int](https://github.com/sindresorhus/random-int) - Generate a random integer\n- [random-float](https://github.com/sindresorhus/random-float) - Generate a random float\n- [random-item](https://github.com/sindresorhus/random-item) - Get a random item from an array\n- [random-boolean](https://github.com/arthurvr/random-boolean) - Get a random boolean\n- [random-obj-key](https://github.com/sindresorhus/random-obj-key) - Get a random key from an object\n- [random-obj-prop](https://github.com/sindresorhus/random-obj-prop) - Get a random property from an object\n- [unique-random](https://github.com/sindresorhus/unique-random) - Generate random numbers that are consecutively unique\n\n---\n\n<div align=\"center\">\n\t<b>\n\t\t<a href=\"https://tidelift.com/subscription/pkg/npm-crypto-random-string?utm_source=npm-crypto-random-string&utm_medium=referral&utm_campaign=readme\">Get professional support for this package with a Tidelift subscription</a>\n\t</b>\n\t<br>\n\t<sub>\n\t\tTidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.\n\t</sub>\n</div>\n","_attachments":{},"homepage":"https://github.com/sindresorhus/crypto-random-string#readme","bugs":{"url":"https://github.com/sindresorhus/crypto-random-string/issues"},"license":"MIT"}