generate-string is a string generator that build random strings, strings with mask and passwords with password-strength tester. It is lightweight, extensible, has no dependencies, and can be used on the server with NodeJS or in-browser with JS.
From the command line:
npm install generate-strings --saveWithin your document:
<script src="generate-strings.js"></script>- Generate random strings (default) like below:
,9nlg4^]- Generate strings with mask like below:
'@#$%-@#$%-@#$%-@#$%' = 'Aa!0-Aa!0-Aa!0-Aa!0'- Generate passwords with password-strength tester like below:
{ password: '2dt4hKIPO*=He', strength: 'high' }After you've included it into your project, using the module is straightforward:
// require the module const str = require('generate-strings') console.log(str.generate())// in the browser, including the script will make a generate() function available. console.log(generate())The module may be configured as follows: OBS: The settings shown below are the defaults.
const str = require('generate-strings') // Pass a hash of settings into an object. let settings = { // available settings will be shown below } // and then: let string = str.generate(settings)| Name | Type | Description | Default value | Allowed values |
|---|---|---|---|---|
| amount | Integer | Amount of strings to generate | 1 | 0-Number.MAX_SAFE_INTEGER |
| mode | String | Different modes to generate a string | 'random' | 'random', 'mask', 'password' |
| upperCases | String | UpperCase letters to be generate | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | 'A-Z' |
| lowerCases | String | LowerCase letters to be generate | 'abcdefghijklmnopqrstuvwxyz' | 'a-z' |
| specials | String | Special letters to be generate | '!@#$%&*()=[]{}' | All special characters |
| numbers | String | Numbers to be generate | '0123456789' | 0-9 |
| Name | Type | Description | Default value | Allowed values |
|---|---|---|---|---|
| length | Integer | Size of the strings that will be generated | 8 | 0-Number.MAX_SAFE_INTEGER |
| upperCase | Boolean | Determines whether it will be generated | true | true and false |
| lowerCase | Boolean | Determines whether it will be generated | true | true and false |
| special | Boolean | Determines whether it will be generated | false | true and false |
| number | Boolean | Determines whether it will be generated | true | true and false |
| Name | Type | Description | Default value | Allowed values |
|---|---|---|---|---|
| showStrength | Boolean | Shows the password strength | false | true and false |
| firstCharType | String | Determines the type of first character | 'random' | 'random', 'upperCase', 'lowerCase', 'special', 'number' |
| excludeEqualChars | Boolean | Excludes characters that are equals | true | true and false |
| Name | Type | Description | Default value | Allowed values |
|---|---|---|---|---|
| mask | String | Mask to string that will be generated | '@#$%-@#$%-@#$%-@#$%' | * |
| upperCaseMask | String | Letter that will be replaced a upperCase char | '@' | '*' |
| lowerCaseMask | String | Letter that will be replaced a upperCase char | '#' | '*' |
| specialMask | String | Letter that will be replaced a upperCase char | '$' | '*' |
| numberMask | String | Letter that will be replaced a upperCase char | '%' | '*' |
To run the test, simply type cd into directory and run npm test. You may first need to run npm install to install the required development dependencies. (These dependencies are not required in a production environment, and facilitate only unit testing.)
If you'd like to contribute, please fork this repository, change the branch typing git checkout dev, make a new branch typing git checkout -b branchName, make your changes, make a push typing git push -u origin branchName and then submit a pull-request.
