random-strr
v1.0.0
Published
Return a random string.
Downloads
43
Maintainers
Readme
random-strr
Return a random string.
Install
$ npm install --save random-strr
Usage
var randomString = require('random-strr');
// API
// - randomString([options]);
// options
// - pool
// - length
// - min
// - max
By default it will return a string with random length of 5-20
characters and will contain any of the following characters.
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&()*_+-={}[]'
Can optionally specify a length and the string will be exactly that length:
randomString({ length: 5 });
// => 'YN%fG'
Can optionally specify min, max, or both to limit the range.
randomString({ min: 8 });
// => huepevesik
randomString({ max: 10 });
// => biwuwkef
randomString({ min: 10, max: 40 });
// => omoemowawahteze
Can optionally specify a pool and the string will be generated with characters only from that pool.
randomString({ pool: 'abcde' });
// => 'cccdeeabedebb'
Of course these options can be combined.
randomString({ length: 5, pool: 'abcde' });
=> 'cbbdc'
Related
- random-integral - Return a random integer.
- random-natural - Return a random natural number.
- random-decimal - Return a random decimal.
- random-floating - Return a random floating point number.
- random-index - Return a random array-like index.
- random-binary - Return a random binary number.
- random-octal - Return a random octal number.
- random-hexadecimal - Return a random hexadecimal number.
- random-unicode - Return a random unicode.
- random-bool - Return a random boolean (true/false).
- random-char - Return a random char.
Contributing
Pull requests and stars are highly welcome.
For bugs and feature requests, please create an issue.