diff --git a/README.md b/README.md index 1d4d165..83aa48b 100644 --- a/README.md +++ b/README.md @@ -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^] @@ -58,7 +58,7 @@ 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 @@ -66,32 +66,32 @@ 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 /* ************************************************* @@ -99,19 +99,20 @@ const settings = { ************************************************** */ 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 /* ************************************************* @@ -119,32 +120,49 @@ const settings = { ************************************************* */ 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 @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/dist/generate-strings.js b/dist/generate-strings.js deleted file mode 100644 index 8daf44a..0000000 --- a/dist/generate-strings.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = -/******/ (function(modules, runtime) { // webpackBootstrap -/******/ "use strict"; -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(977); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ 977: -/***/ (function(__unusedmodule, exports) { - -'use-strict';(function(a,b){'function'==typeof define&&define.amd?define([],b): true?exports.generate=b:undefined})(this,function(a={}){let b='',c=a.amount===void 0?1:a.amount;const d=!(a.upperCase!==void 0)||a.upperCase,e=a.upperCases===void 0?'ABCDEFGHIJKLMNOPQRSTUVWXYZ':a.upperCases,f=!(a.lowerCase!==void 0)||a.lowerCase,g=a.lowerCases===void 0?'abcdefghijklmnopqrstuvwxyz':a.lowerCases,h=a.special!==void 0&&a.special,j=a.specials===void 0?'!@#$%&*()=[]{}':a.specials,k=!(a.number!==void 0)||a.number,l=a.numbers===void 0?'0123456789':a.numbers,m=a.mode===void 0?'random':a.mode;if(!(0 0');if('random'===m){const n=void 0===a.length?8:a.length,o=(!0===d?e:'')+(!0===f?g:'')+(!0===h?j:'')+(!0===k?l:''),p=[];if(''===o)throw new Error('You must set at least 1 character type for generate a random string');do{for(let q=0;qn)throw new Error('Length should be > 5');do{if('upperCase'===p){if(''===e)throw new Error('Set at least 1 character for upperCase');b+=e[parseInt(Math.random()*e.length)]}else if('lowerCase'===p){if(''===g)throw new Error('Set at least 1 character for lowerCase');b+=g[parseInt(Math.random()*g.length)]}else if('special'===p){if(''===j)throw new Error('Set at least 1 character for special');b+=j[parseInt(Math.random()*j.length)]}else if('number'===p){if(''===l)throw new Error('Set at least 1 character for number');b+=l[parseInt(Math.random()*l.length)]}else b+=q[parseInt(Math.random()*q.length)];for(let t,s=0;sb?'unacceptable':60>b?'terrible':80>b?'medium':100>b?'good':'high'} - -/***/ }) - -/******/ }); \ No newline at end of file diff --git a/generate-strings.js b/generate-strings.js index 1d2d14e..ee38e12 100644 --- a/generate-strings.js +++ b/generate-strings.js @@ -1 +1 @@ -'use-strict';(function(a,b){'function'==typeof define&&define.amd?define([],b):'object'==typeof exports?exports.generate=b:a.generate=b})(this,function(a={}){let b='',c=a.amount===void 0?1:a.amount;const d=!(a.upperCase!==void 0)||a.upperCase,e=a.upperCases===void 0?'ABCDEFGHIJKLMNOPQRSTUVWXYZ':a.upperCases,f=!(a.lowerCase!==void 0)||a.lowerCase,g=a.lowerCases===void 0?'abcdefghijklmnopqrstuvwxyz':a.lowerCases,h=a.special!==void 0&&a.special,j=a.specials===void 0?'!@#$%&*()=[]{}':a.specials,k=!(a.number!==void 0)||a.number,l=a.numbers===void 0?'0123456789':a.numbers,m=a.mode===void 0?'random':a.mode;if(!(0 0');if('random'===m){const n=void 0===a.length?8:a.length,o=(!0===d?e:'')+(!0===f?g:'')+(!0===h?j:'')+(!0===k?l:''),p=[];if(''===o)throw new Error('You must set at least 1 character type for generate a random string');do{for(let q=0;qn)throw new Error('Length should be > 5');do{if('upperCase'===p){if(''===e)throw new Error('Set at least 1 character for upperCase');b+=e[parseInt(Math.random()*e.length)]}else if('lowerCase'===p){if(''===g)throw new Error('Set at least 1 character for lowerCase');b+=g[parseInt(Math.random()*g.length)]}else if('special'===p){if(''===j)throw new Error('Set at least 1 character for special');b+=j[parseInt(Math.random()*j.length)]}else if('number'===p){if(''===l)throw new Error('Set at least 1 character for number');b+=l[parseInt(Math.random()*l.length)]}else b+=q[parseInt(Math.random()*q.length)];for(let t,s=0;sb?'unacceptable':60>b?'terrible':80>b?'medium':100>b?'good':'high'} \ No newline at end of file +(function(a,b){'function'==typeof define&&define.amd?define([],b):'object'==typeof exports?exports.generate=b:a.generate=b})(this,function(a={}){let b='',c=a.amount===void 0?1:a.amount;const d=!(a.upperCase!==void 0)||a.upperCase,e=a.upperCases===void 0?'ABCDEFGHIJKLMNOPQRSTUVWXYZ':a.upperCases,f=!(a.lowerCase!==void 0)||a.lowerCase,g=a.lowerCases===void 0?'abcdefghijklmnopqrstuvwxyz':a.lowerCases,h=a.special!==void 0&&a.special,j=a.specials===void 0?'!@#$%&*()=[]{}':a.specials,k=!(a.number!==void 0)||a.number,l=a.numbers===void 0?'0123456789':a.numbers,m=a.mode===void 0?'random':a.mode;if(!(0 0');if('random'===m){const n=void 0===a.length?8:a.length,o=(!0===d?e:'')+(!0===f?g:'')+(!0===h?j:'')+(!0===k?l:''),p=[];if(''===o)throw new Error('You must set at least 1 character type for generate a random string');do{for(let q=0;qn)throw new Error('Length must be > 1');do{if('upperCase'===p){if(''===e)throw new Error('Set at least 1 character for upperCase');b+=e[parseInt(Math.random()*e.length)]}else if('lowerCase'===p){if(''===g)throw new Error('Set at least 1 character for lowerCase');b+=g[parseInt(Math.random()*g.length)]}else if('special'===p){if(''===j)throw new Error('Set at least 1 character for special');b+=j[parseInt(Math.random()*j.length)]}else if('number'===p){if(''===l)throw new Error('Set at least 1 character for number');b+=l[parseInt(Math.random()*l.length)]}else b+=r[parseInt(Math.random()*r.length)];for(let u,t=0;tb?'unacceptable':60>b?'terrible':80>b?'medium':100>b?'good':'high'} \ No newline at end of file diff --git a/package.json b/package.json index 4531672..8f34f4a 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } \ No newline at end of file diff --git a/test.js b/test.js index f56eb8f..5537465 100644 --- a/test.js +++ b/test.js @@ -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) \ No newline at end of file +console.log('\n\nGenerating a random string with mask:\n', stringWithMask) \ No newline at end of file