{"id":13515282,"url":"https://github.com/sindresorhus/crypto-random-string","last_synced_at":"2025-04-13T02:00:04.427Z","repository":{"id":37396538,"uuid":"73665728","full_name":"sindresorhus/crypto-random-string","owner":"sindresorhus","description":"Generate a cryptographically strong random string","archived":false,"fork":false,"pushed_at":"2022-05-10T06:15:39.000Z","size":29,"stargazers_count":571,"open_issues_count":0,"forks_count":43,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-11T00:43:49.261Z","etag":null,"topics":["crypto","javascript","npm-package","random","random-string","random-string-generators"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2016-11-14T04:06:00.000Z","updated_at":"2025-03-17T02:03:58.000Z","dependencies_parsed_at":"2022-07-12T12:49:45.989Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/crypto-random-string","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcrypto-random-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcrypto-random-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcrypto-random-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcrypto-random-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/crypto-random-string/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248530564,"owners_count":21119599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crypto","javascript","npm-package","random","random-string","random-string-generators"],"created_at":"2024-08-01T05:01:08.804Z","updated_at":"2025-04-13T02:00:04.407Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# crypto-random-string\n\n\u003e 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//=\u003e '2cf05d94db'\n\ncryptoRandomString({length: 10, type: 'base64'});\n//=\u003e 'YMiMbaQl6I'\n\ncryptoRandomString({length: 10, type: 'url-safe'});\n//=\u003e 'YN-tqc8pOw'\n\ncryptoRandomString({length: 10, type: 'numeric'});\n//=\u003e '8314659141'\n\ncryptoRandomString({length: 6, type: 'distinguishable'});\n//=\u003e 'CDEHKM'\n\ncryptoRandomString({length: 10, type: 'ascii-printable'});\n//=\u003e '`#Rt8$IK\u003eB'\n\ncryptoRandomString({length: 10, type: 'alphanumeric'});\n//=\u003e 'DMuKL8YtE7'\n\ncryptoRandomString({length: 10, characters: 'abc'});\n//=\u003e '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\u003e 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//=\u003e '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): ``!\"#$%\u0026\\'()*+,-./0123456789:;\u003c=\u003e?@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\u003cdiv align=\"center\"\u003e\n\t\u003cb\u003e\n\t\t\u003ca href=\"https://tidelift.com/subscription/pkg/npm-crypto-random-string?utm_source=npm-crypto-random-string\u0026utm_medium=referral\u0026utm_campaign=readme\"\u003eGet professional support for this package with a Tidelift subscription\u003c/a\u003e\n\t\u003c/b\u003e\n\t\u003cbr\u003e\n\t\u003csub\u003e\n\t\tTidelift helps make open source sustainable for maintainers while giving companies\u003cbr\u003eassurances about security, maintenance, and licensing for their dependencies.\n\t\u003c/sub\u003e\n\u003c/div\u003e\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate","https://tidelift.com/subscription/pkg/npm-crypto-random-string?utm_source=npm-crypto-random-string\u0026utm_medium=referral\u0026utm_campaign=readme"],"categories":["JavaScript","Javascript Libraries","Helper Components","Generation"],"sub_categories":["JavaScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcrypto-random-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fcrypto-random-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcrypto-random-string/lists"}