1.0.5 • Published 1 year ago

custom-rand-str v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

custom-rand-str

A Library to help you create a customized random string by using different options.

Installation

Use the package manager npm to install customized random string.

npm install custom-rand-str

Usage

const randomSring = require('custom-rand-str');

randomSring();  // no special characters by default
// 6G0YgT7l427fc4792y7nFS6T

// specify number of alphabets and digits in the string
randomSring({ noOfAlphabets: 5, noOfDigits: 5 });
// 3q0F2E2ep9

// include special characters in the string
randomSring({ noOfAlphabets: 6, noOfDigits: 6, noOfSpecialCharacters: 10 });
// (fS(R;R@15$[9a$6|,7#5q

// generate a string with your choice of characters order
randomSring({ noOfAlphabets: 5, noOfDigits: 5, noOfSpecialCharacters: 8, order: "alphabets-specialchars-num" });
// nCrFb.\>(-$'[26836

// generate a string with only capital letters
randomSring({ alphabetsType: "capital" });
// 437G9TO5JQ671TFM4R5EIM31

// Excluding single or multiple characters by using excludeChars
randomSring({ exludeChars: "abcdeEf12345" });
// 00u8gM86yypB0xX7097kJ70Y

Options

OptionTypePossible valuesDefault value
noOfDigitsNumberany positive integer12
noOfAlphabetsNumberany positive integer12
noOfSpecialCharactersNumberany positive integer0
alphabetsTypeStringmixedsmallcapitalmixed
orderStringnum-specialchars-alphabetsnum-alphabets-specialcharsspecialchars-alphabets-numspecialchars-num-alphabetsalphabets-num-specialcharsalphabets-num-specialcharsmixedmixed
exludeCharsStringsingle or multiple charactersundefined

Tests

Use the following commands to test the library

npm test
npm run coverage
npm run test:watch

License

MIT