0.1.0 • Published 7 years ago

random-plus v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

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)
    1. The string or array which takes non-multilple characters of each type.
      • A stands for capital letters (A - Z),
      • a stands for small letters (a - z),
      • D or d stands for digits (0 - 9),
      • S stands for special symbols ( !"#$%&\'()*+,-./:;<=>?@\^_`{|}~ ),
      • s stands for safe special symbols ( !#$%&*+,-.=?@^_~ ).
    2. The optional length of the output string, default is 8.

  • The generatePlus(object) method takes options argument to generate string of random characters. It expects 1 object argument with following properties
    1. length: The length of the returned random string. Default is 8
    2. pattern: The pattern, same as the first argument of generate() method.
    3. 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 be AA. 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: AdA is invalid.
    4. end: The pattern for the end, just like the start
    5. startsWith: The static string that will be added at the beginning of the returned string.
    6. 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"})); //Ycz7fhx9

Developed by @abhishekp1996. For any issues, let me know on abhishekp1996[@]gmail[.]com