Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgdb committed Jan 3, 2019
1 parent 8cb0691 commit 89468d1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 86 deletions.
61 changes: 39 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ After you've included it into your project, using the module is straightforward:
### Server-side
```javascript
// require the module
const str = require('generate-strings');
const str = require('generate-strings')
// invoke generate() to generate a random string
const string = str.generate(/* settings into object */)
let string = str.generate(/* settings into object */)
// shows the result
console.log(string) // something like ,9nlg4^]
Expand All @@ -58,93 +58,111 @@ console.log(string) // something like ,9nlg4^]
### In-browser
```javascript
// in the browser, including the script will make a generate() function available.
const str = generate() // will return a string
let str = generate() // will return a string
```
Configuring
-----------
The module may be configured as follows:
```javascript
const str = require('generate-strings');
const str = require('generate-strings')
// Pass a hash of settings into an object. The settings shown here are the defaults.
const settings = {
let settings = {
/*
*************************************************
Settings for all modes
*************************************************
*/
amount: 1,
// set the amount of strings to generate
// Number, set the amount of strings to generate
mode: 'random',
// set the mode. Allows "random", "mask" and "password"
// String, set the mode. Allows "random", "mask" and "password"
upperCases: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
// upperCases characters
// String, upperCases characters that will be generated
lowerCases: 'abcdefghijklmnopqrstuvwxyz',
// lowerCase characters
// String, lowerCase characters that will be generated
specials: '!@#$%&*()=[]{}',
// special characters
// String, special characters that will be generated
numbers: '0123456789',
// numbers
// String, numbers that will be generated
/*
*************************************************
Settings for random string and password modes
**************************************************
*/
length: 8,
// length of the strings
// Number, length of the strings
// when mode is password, must be > 1
upperCase: true,
// set a boolean value to generate strings with upperCase characters
// Boolean, set a boolean value to generate strings with upperCase characters
lowerCase: true,
// set a boolean value to generate strings with lowerCase characters
// Boolean, set a boolean value to generate strings with lowerCase characters
special: false,
// set a boolean value to generate strings with special characters
// Boolean, set a boolean value to generate strings with special characters
number: true,
// set a boolean value to generate strings with numbers
// Boolean, set a boolean value to generate strings with numbers
/*
*************************************************
Settings for password mode
*************************************************
*/
showStrength: false,
// Shows the password strength
// Boolean, shows the password strength
// like: strength: high. Possible results: unacceptable, terrible, medium, good and high.
firstCharType: 'random',
// set the type of first character when generate a password
// String, set the type of first character when generate a password
// 'random' - random type
// 'upperCase' - to upperCase character
// 'lowerCase' - to lowerCase character
// 'special' - to special character
// 'number' - to number
excludeEqualChars: true,
// Boolean, exclude characters that are equals
// E.g: aa, AA, @@, 00
/*
*************************************************
Settings for mask mode
*************************************************
*/
mask: '@#$%-@#$%-@#$%-@#$%' // mask of string
mask: '@#$%-@#$%-@#$%-@#$%',
// String, mask to generate the strings
// @ - to upperCase characters
// # - to lowerCase characters
// $ - to special characters
// % - to numbers
// others: no will be changed
upperCaseMask: '@',
// String, must be 1 character
lowerCaseMask: '#',
// String, must be 1 character
specialMask: '$',
// String, must be 1 character
numberMask: '%'
// String, must be 1 character
}
// and then:
const string = str.generate(settings)
let string = str.generate(settings)
```

Testing
Expand All @@ -154,7 +172,6 @@ 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.)


Contributing
------------
If you'd like to contribute, please fork this repository, change the default branch typing git checkout dev, make your changes, and then submit a pull-request.
If you'd like to contribute, please fork this repository, change the default branch typing git checkout dev, make your changes, make a new branch and then submit a pull-request.
47 changes: 0 additions & 47 deletions dist/generate-strings.js

This file was deleted.

2 changes: 1 addition & 1 deletion generate-strings.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generate-strings",
"version": "1.0.6",
"version": "1.1.0",
"description": "Generate random strings, strings with mask and strength passwords with password-strength tester",
"main": "generate-strings.js",
"scripts": {
Expand All @@ -27,8 +27,5 @@
"bugs": {
"url": "https://github.com/LucasNaja/generate-strings/issues"
},
"homepage": "https://github.com/LucasNaja/generate-strings#readme",
"devDependencies": {
"@zeit/ncc": "^0.8.1"
}
"homepage": "https://github.com/LucasNaja/generate-strings#readme"
}
26 changes: 15 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@ const str = require('./generate-strings')
const randomString = str.generate({
amount: 3,
special: true,
length: 20
length: 10
})

console.log('Generating a random string: ', randomString)
console.log('Generating a random string:\n', randomString)

const password = str.generate({
mode: 'password',
length: 12,
amount: 10,
length: 6,
special: true,
showStrength: true
showStrength: true,
excludeEqualChars: false
})

console.log('\n\nGenerating a random password: ', password)
console.log('\n\nGenerating a random password:\n', password)

const stringWithMask = str.generate({
mode: 'mask',
mask: 'String mask: @ # $ %',
upperCases: 'A',
lowerCases: 'a',
upperCaseMask: '&',
lowerCaseMask: '0',
mask: 'i\'m a string mask, and the result is: & 0 @ # $ %',
upperCases: 'ABCDEF',
lowerCases: 'abcdef',
special: true,
specials: '+',
numbers: '0'
specials: '+-=[]~',
numbers: '012345',
})

console.log('\n\nGenerating a random string with mask: ', stringWithMask)
console.log('\n\nGenerating a random string with mask:\n', stringWithMask)

0 comments on commit 89468d1

Please sign in to comment.