[The repo is archived because nobody reads the release notes] [It will be unarchived again in a month] Generate a cryptographically strong random string
Installations
npm install crypto-random-string-with-promisify-polyfill
Developer Guide
Typescript
No
Module System
N/A
Min. Node Version
>=8
Node Version
16.3.0
NPM Version
7.19.0
Score
74.5
Supply Chain
98.9
Quality
75
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (93.78%)
TypeScript (6.22%)
Developer
wolfflow
Download Statistics
Total Downloads
216,738
Last Day
388
Last Week
1,714
Last Month
7,184
Last Year
89,058
GitHub Statistics
30 Commits
2 Watching
1 Branches
1 Contributors
Bundle Size
3.66 kB
Minified
1.48 kB
Minified + Gzipped
Package Meta Information
Latest Version
5.0.0
Package Id
crypto-random-string-with-promisify-polyfill@5.0.0
Unpacked Size
14.14 kB
Size
4.30 kB
File Count
5
NPM Version
7.19.0
Node Version
16.3.0
Total Downloads
Cumulative downloads
Total Downloads
216,738
Last day
30.2%
388
Compared to previous day
Last week
7.2%
1,714
Compared to previous week
Last month
28.2%
7,184
Compared to previous month
Last year
119.6%
89,058
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
crypto-random-string
Generate a cryptographically strong random string
Can be useful for creating an identifier, slug, salt, PIN code, fixture, etc.
Install
$ npm install crypto-random-string
Usage
1const cryptoRandomString = require('crypto-random-string'); 2 3cryptoRandomString({length: 10}); 4//=> '2cf05d94db' 5 6cryptoRandomString({length: 10, type: 'base64'}); 7//=> 'YMiMbaQl6I' 8 9cryptoRandomString({length: 10, type: 'url-safe'}); 10//=> 'YN-tqc8pOw' 11 12cryptoRandomString({length: 10, type: 'numeric'}); 13//=> '8314659141' 14 15cryptoRandomString({length: 6, type: 'distinguishable'}); 16//=> 'CDEHKM' 17 18cryptoRandomString({length: 10, type: 'ascii-printable'}); 19//=> '`#Rt8$IK>B' 20 21cryptoRandomString({length: 10, type: 'alphanumeric'}); 22//=> 'DMuKL8YtE7' 23 24cryptoRandomString({length: 10, characters: 'abc'}); 25//=> 'abaaccabac'
API
cryptoRandomString(options)
Returns a randomized string. Hex by default.
cryptoRandomString.async(options)
Returns a promise which resolves to a randomized string. Hex by default.
options
Type: object
length
Required
Type: number
Length of the returned string.
type
Type: string
Default: 'hex'
Values: 'hex' | 'base64' | 'url-safe' | 'numeric' | 'distinguishable' | 'ascii-printable' | 'alphanumeric'
Use only characters from a predefined set of allowed characters.
Cannot be set at the same time as the characters
option.
The 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.
The ascii-printable
set contains all printable ASCII characters: !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Useful for generating passwords where all possible ASCII characters should be used.
The alphanumeric
set contains uppercase letters, lowercase letters, and digits: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
. Useful for generating nonce values.
characters
Type: string
Minimum length: 1
Maximum length: 65536
Use only characters from a custom set of allowed characters.
Cannot be set at the same time as the type
option.
Related
- random-int - Generate a random integer
- random-float - Generate a random float
- random-item - Get a random item from an array
- random-boolean - Get a random boolean
- random-obj-key - Get a random key from an object
- random-obj-prop - Get a random property from an object
- unique-random - Generate random numbers that are consecutively unique
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
No vulnerabilities found.
No security vulnerabilities found.