Simple Module for generating Random Strings
npm install random-stringSimple Module for generating Random Strings
npm install random-string``javascript`
var randomString = require('random-string');
var x = randomString(); // x contains now a random String with the length of 8
You can call the randomString-Method with additional options for specifing how long your resulting string should be and which characters to include
`javascript`
// e.g. you want a string with a length of 20
var x = randomString({length: 20});
#### options.length
number - the length of your resulting string (DEFAULT: 8)
#### options.numeric
boolean - should your resulting string contain numbers (from 0-9) (DEFAULT: true)
#### options.letters
boolean - should your resulting string contain letters (from a-z, lower and uppercase) (DEFAULT: true)
#### options.special
boolean - should your resulting string contain any of these special characters (!$%^&*()_+|~-=\{}[]:;<>?,./) (DEFAULT: false)
#### options.exclude
array - removes characters from resulting string
Note: Lowercase letters will not remove uppercase letters
``javascript`
// that would be a call with all options (hint: thats a call with all defaults, und the options wouldnt be necessary in that case!)
var x = randomString({
length: 8,
numeric: true,
letters: true,
special: false,
exclude: ['a', 'b', '1']
});
- 0.2.0 introduce exclude`-option
- 0.1.2 fix characterset (#2)
- 0.1.1 do not contain special cars per default
- 0.1.0 Initial Release
- Bastian "hereandnow" Behrens
- Baran "bjskistad" Skistad