0.1.0 • Published 8 years ago
random-plus v0.1.0
Random-plus
A npm module to generate string of random characters
Usage
Import the module, using require('random-plus').
const randomPlus = require('random-plus');There are 2 methods, .generate() and .generatePlus().
- The
generate(string, number)method is a faster way to generate string of random characters. It expects 2 arguments (length is optional)- The string or array which takes non-multilple characters of each type.
Astands for capital letters (A - Z),astands for small letters (a - z),Dordstands for digits (0 - 9),Sstands for special symbols ( !"#$%&\'()*+,-./:;<=>?@\^_`{|}~ ),sstands for safe special symbols ( !#$%&*+,-.=?@^_~ ).
- The optional
lengthof the output string, default is 8.
- The string or array which takes non-multilple characters of each type.
- The
generatePlus(object)method takes options argument to generate string of random characters. It expects 1 object argument with following propertieslength: The length of the returned random string. Default is 8pattern: The pattern, same as the first argument ofgenerate()method.start: The pattern for the start of the random string. If there are required 2 random capital letters in the beginning, the value of this property should beAA. The number of times is the length of the string that starts with this pattern. Note, only first pattern type is valid, ie, you can't mix, ex:AdAis invalid.end: The pattern for the end, just like thestartstartsWith: The static string that will be added at the beginning of the returned string.endsWith: The static string that will be appended at the end of the returned string.
Note that length of returned string is exclusive of startsWith and endsWith in case of generatePlus() method.
Examples
To demonstarte the usage.
let randomPlus = require('random-plus');
//Only Capital letters
console.log(randomPlus.generate("A")); //RUOWUSBW
//Only small letters and digits
console.log(randomPlus.generate("aD"), 4); //e29p
//Only small letters, digits and safe symbols
console.log(randomPlus.generate("ads", 10)); //8e01uh+h=7
//Customizing the options
var options = {
length: 6,
pattern: "a",
start: "AA",
end: "dd",
startsWith: "image-",
endsWith: ".jpg"
};
console.log(rp.generatePlus(options)); //image-XGbr08.jpg
//Direct options object
console.log(rp.generatePlus({pattern: "ad", start: "A"})); //Ycz7fhx9Developed by @abhishekp1996.
For any issues, let me know on abhishekp1996[@]gmail[.]com