generate-pw 1.2.2 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
  ### Randomly generate cryptographically-secure passwords.
18
18
 
19
19
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
20
- <a href="https://github.com/adamlui/js-utils/releases/tag/generate-pw-1.2.2"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.2.2-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
20
+ <a href="https://github.com/adamlui/js-utils/releases/tag/generate-pw-1.3.1"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.3.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
21
21
  <a href="https://www.npmjs.com/package/generate-pw?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/generate-pw?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
22
22
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-pw/generate-pw.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-pw%2Fgenerate-pw.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
23
23
 
@@ -68,7 +68,15 @@ Generates **one** password if `qty` option is not given, returning a string:
68
68
  ```js
69
69
  const password = pw.generatePassword({ length: 11, numbers: true });
70
70
  console.log(password);
71
- // sample output: 'bAsZm3mq6Qn'
71
+
72
+ /* sample output:
73
+
74
+ generatePassword() » Initializing character set...
75
+ generatePassword() » Generating password...
76
+ generatePassword() » Password generated!
77
+ generatePassword() » Check returned string.
78
+ 'bAsZm3mq6Qn'
79
+ */
72
80
  ```
73
81
 
74
82
  ...or **multiple** passwords if `qty` option is given, returning an array of strings:
@@ -76,7 +84,14 @@ console.log(password);
76
84
  ```js
77
85
  const passwords = pw.generatePassword({ qty: 5, length: 8, symbols: true });
78
86
  console.log(passwords);
79
- // sample output: [ '!zSf@Q.s', '!,HT\\;m=', '?Lq&FV>^', 'gf}Y;}Ne', 'Stsx(GqE' ]
87
+
88
+ /* sample output:
89
+
90
+ generatePassword() » Generating passwords...
91
+ generatePassword() » Passwords generated!
92
+ generatePassword() » Check returned array.
93
+ [ '!zSf@Q.s', '!,HT\\;m=', '?Lq&FV>^', 'gf}Y;}Ne', 'Stsx(GqE' ]
94
+ */
80
95
  ```
81
96
 
82
97
  **💡 Note:** If no options are passed, passwords will be 8-chars long, consisting of upper/lower cased letters.
@@ -92,7 +107,14 @@ Generates **multiple** passwords based on `qty` given, returning an array of str
92
107
  ```js
93
108
  const passwords = pw.generatePasswords(5, { length: 3, uppercase: false });
94
109
  console.log(passwords);
95
- // sample output: [ 'yilppxru', 'ckvkyjfp', 'zolcpyfb' ]
110
+
111
+ /* sample output:
112
+
113
+ generatePasswords() » Generating passwords...
114
+ generatePasswords() » Passwords generated!
115
+ generatePasswords() » Check returned array.
116
+ [ 'yilppxru', 'ckvkyjfp', 'zolcpyfb' ]
117
+ */
96
118
  ```
97
119
 
98
120
  **💡 Note:** If no `qty` arg is passed, just one password will be generated, returned as a string.
@@ -101,25 +123,36 @@ See: [Available options](#available-options-for-generate-functions)
101
123
 
102
124
  #
103
125
 
104
- ### `strictify(password[, requiredCharTypes])`
126
+ ### `strictify(password[, requiredCharTypes, options])`
105
127
 
106
128
  Modifies `password` given to use at least one character of each `requiredCharTypes` element passed, returning a string:
107
129
 
108
130
  ```js
109
- const password = 'abcdef',
110
- strictPW = pw.strictify(password, ['numbers', 'symbols']);
111
-
131
+ const strictPW = pw.strictify('abcdef', ['numbers', 'symbols']);
112
132
  console.log(strictPW);
113
- // sample output: 'a!c2ef'
133
+
134
+ /* sample output:
135
+
136
+ strictify() » Strictifying password...
137
+ strictify() » Password is now strict!
138
+ strictify() » Check returned string.
139
+ a!c2ef
140
+ */
114
141
  ```
115
142
 
143
+ **💡 Note:** If no `requiredCharTypes` array is passed, all available types will be required.
144
+
116
145
  Available `requiredCharTypes` are: `['number', 'symbol', 'lower', 'upper']`
117
146
 
118
- **💡 Note:** If no `requiredCharTypes` array is passed, all available types will be required.
147
+ Available options (passed as object properties):
148
+
149
+ Name | Type | Description | Default Value
150
+ ----------|---------|-----------------------------------|---------------
151
+ `verbose` | Boolean | Show logging in console/terminal. | `true`
119
152
 
120
153
  #
121
154
 
122
- ### `validateStrength(password)`
155
+ ### `validateStrength(password[, options])`
123
156
 
124
157
  Validates the strength of a password, returning an object containing:
125
158
  - `strengthScore` (0–100)
@@ -129,21 +162,31 @@ Validates the strength of a password, returning an object containing:
129
162
  Example:
130
163
 
131
164
  ```js
132
- const password = 'AawiddsE',
133
- pwStrength = pw.validateStrength(password);
134
-
165
+ const pwStrength = pw.validateStrength('Aa?idsE');
135
166
  console.log(pwStrength);
136
167
 
137
168
  /* outputs:
138
169
 
170
+ validateStrength() » Validating password strength...
171
+ validateStrength() » Password strength validated!
172
+ validateStrength() » Check returned object for score/recommendations.
139
173
  {
140
174
  strengthScore: 60,
141
- recommendations: [ 'Include at least one number.', 'Include at least one symbol.' ],
175
+ recommendations: [
176
+ 'Make it at least 8 characters long.',
177
+ 'Include at least one number.'
178
+ ],
142
179
  isGood: false
143
180
  }
144
181
  */
145
182
  ```
146
183
 
184
+ Available options (passed as object properties):
185
+
186
+ Name | Type | Description | Default Value
187
+ ----------|---------|-----------------------------------|---------------
188
+ `verbose` | Boolean | Show logging in console/terminal. | `true`
189
+
147
190
  #
148
191
 
149
192
  ### Available options for `generate*()` functions
@@ -152,6 +195,7 @@ Any of these can be passed into the options object for each `generate*()` functi
152
195
 
153
196
  Name | Type | Description | Default Value
154
197
  ------------|---------|--------------------------------------------------------------------------------|---------------
198
+ `verbose` | Boolean | Enable logging. | `true`
155
199
  `length` | Integer | Length of password(s). | `8`
156
200
  `qty`* | Integer | Number of passwords to generate. | `1`
157
201
  `charset` | String | Characters to include in password(s). | `''`
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env node
2
- const p=require("crypto")["randomInt"],s=require("child_process")["execSync"],u={lower:"abcdefghijklmnopqrstuvwxyz",upper:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",numbers:"0123456789",symbols:"!@#$%^&*()-_=+[]{}/\\|;:'\",.<>?"};function a(o={}){var e,s={length:8,qty:1,charset:"",exclude:"",numbers:!1,symbols:!1,lowercase:!0,uppercase:!0,strict:!1};o={...s,...o};for(const r of Object.keys(o))if(!Object.prototype.hasOwnProperty.call(s,r))return console.error(`generatePassword() » ERROR: \`${r}\` is an invalid option.`+`
3
- generatePassword() » Valid options:
4
- [ ${Object.keys(s).join(", ")} ]`);for(const n of["length","qty"])if(isNaN(o[n])||o[n]<1)return console.error(`generatePassword() » ERROR: [${n}] option must be > 1.`);for(const a of["numbers","symbols","lowercase","uppercase","strict"])if("boolean"!=typeof o[a])return console.error(`generatePassword() » ERROR: [${a}] option can only be \`true\` or \`false\`.`);if(1<o.qty){const{qty:l,...c}=o;return i(l,c)}{let s=o.charset||(o.numbers?u.numbers:"")+(o.symbols?u.symbols:"")+(o.lowercase?u.lower:"")+(o.uppercase?u.upper:""),r=(s=(s=""===s?u.lower+u.upper:s).replace(new RegExp(`[${o.exclude}]`,"g"),""),"");for(let e=0;e<o.length;e++){var t=p(0,s.length);r+=s.charAt(t)}return o.strict&&(e=["number","symbol","lower","upper"].filter(e=>o[e+"s"]||o[e+"case"]),r=m(r,e)),r}}function i(s,r={}){var e={length:8,qty:1,charset:"",exclude:"",numbers:!1,symbols:!1,lowercase:!0,uppercase:!0,strict:!1};if(r={...e,...r},s=parseInt(s),isNaN(s))return console.error("generatePasswords() » ERROR: First argument [qty] of generatePasswords() must be an integer");for(const t of Object.keys(r))if(!Object.prototype.hasOwnProperty.call(e,t))return console.error(`generatePasswords() » ERROR: \`${t}\` is an invalid option.`+`
5
- generatePassword() » Valid options:
6
- [ ${Object.keys(e).join(", ")} ]`);if(isNaN(r.length)||r.length<1)return console.error("generatePasswords() » ERROR: [length] options must be > 1.");for(const n of["numbers","symbols","lowercase","uppercase","strict"])if("boolean"!=typeof r[n])return console.error(`generatePasswords() » ERROR: [${n}] option can only be \`true\` or \`false\`.`);var o=[];for(let e=0;e<s;e++)o.push(a(r));return o}function m(s,r=["number","symbol","lower","upper"]){for(const l of r)global["has"+l.charAt(0).toUpperCase()+l.slice(1)]=!1;for(let e=0;e<s.length;e++)for(const c of r)(u[c]||u[c+"s"]).includes(s.charAt(e))&&(global["has"+c.charAt(0).toUpperCase()+c.slice(1)]=!0);var e=Math.min(s.length,r.length),o=[];let t=0,n=s;for(const i of r)if(t<e&&!global["has"+i.charAt(0).toUpperCase()+i.slice(1)]){let e;for(;e=p(0,s.length),o.includes(e););o.push(e);var a=u[i]||u[i+"s"];n=n.substring(0,e)+a.charAt(p(0,a.length))+n.substring(e+1),t++}return n}function e(e){var s={minLength:8,minLower:1,minUpper:1,minNumber:1,minSymbol:1},r={lower:0,upper:0,number:0,symbol:0};for(const n of e)for(const a of Object.keys(r))(u[a]||u[a+"s"]).includes(n)&&r[a]++;var o=[];e.length<s.minLength&&o.push(`Make it at least ${s.minLength} characters long.`);for(const l of Object.keys(r))r[l]<s["min"+l.charAt(0).toUpperCase()+l.slice(1)]&&o.push("Include at least one "+l+`${["upper","lower"].includes(l)?"case letter":""}.`);let t=0;t+=e.length>=s.minLength?20:0;for(const c of Object.keys(r))t+=r[c]>=s["min"+c.charAt(0).toUpperCase()+c.slice(1)]?20:0;return{strengthScore:t,recommendations:o,isGood:80<=t}}if(require.main!==module)module.exports={generatePassword:a,generatePasswords:i,strictify:m,validateStrength:e};else{const n="",l="",c="",h={},d={paramOptions:{length:/^--?length/,qty:/^--?qu?a?n?ti?t?y=.*$/,charset:/^--?chars/,excludeChars:/^--?exclude=/},flags:{includeNums:/^--?(?:n|(?:include-?)?num(?:ber)?s?=?(?:true|1)?)$/,includeSymbols:/^--?(?:s|(?:include-?)?symbols?=?(?:true|1)?)$/,excludeLowerChars:/^--?(?:L|(?:exclude|disable|no)-?lower-?(?:case)?|lower-?(?:case)?=(?:false|0))$/,excludeUpperChars:/^--?(?:U|(?:exclude|disable|no)-?upper-?(?:case)?|upper-?(?:case)?=(?:false|0))$/,strictMode:/^--?s(?:trict)?(?:-?mode)?$/},cmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(s=>{var e,r,o;s.startsWith("-")&&(o=Object.keys(d.flags).find(e=>d.flags[e].test(s)),e=Object.keys(d.paramOptions).find(e=>d.paramOptions[e].test(s)),r=Object.keys(d.cmds).find(e=>d.cmds[e].test(s)),o?h[o]=!0:e?(o=s.split("=")[1],h[e]=parseInt(o)||o):r||(console.error(`
7
- ${l}ERROR: Arg [${s}] not recognized.`+n),console.info(`
8
- ${c}Valid arguments are below.`+n),t(["paramOptions","booelanOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>/^--?h(?:elp)?$/.test(e)))t();else if(process.argv.some(e=>/^--?ve?r?s?i?o?n?$/.test(e)))console.info("v"+require("./package.json").version);else{for(const g of["length","qty"])h[g]&&(isNaN(h[g])||h[g]<1)&&(console.error(`
9
- ${l}Error: [${g}] argument must be > 1.`+n),process.exit(1));const o={length:h.length||8,qty:h.qty||1,charset:h.charset,exclude:h.excludeChars,numbers:!!h.includeNums,symbols:!!h.includeSymbols,lowercase:!h.excludeLowerChars,uppercase:!h.excludeUpperChars,strict:!!h.strictMode},f=a(o);r(Array.isArray(f)?f.join("\n"):f)}function t(e=["cmdFormat","paramOptions","booelanOptions","infoCmds"]){const s={cmdFormat:[`
10
- ${c}generate-pw [options|commands]`+n],paramOptions:["\nParameter options:"," --length=n Generate password(s) of n length."," --qty=n Generate n password(s)."," --charset=chars Only include chars in password(s)."," --charset=chars Only include chars in password(s)."," --exclude=chars Exclude chars from password(s)."],booelanOptions:["\nBoolean options:"," -n, --include-numbers Allow numbers in password(s)."," -s, --include-symbols Allow symbols in password(s)."," -L, --no-lowercase Disallow lowercase letters in password(s)."," -U, --no-uppercase Disallow uppercase letters in password(s)."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{s[e]?.forEach(e=>{{const o=process.stdout.columns||80,t=[],s=e.match(/\S+|\s+/g);let r="";s.forEach(e=>{var s=o-(0===t.length?0:29);r.length+e.length>s&&(t.push(0===t.length?r:r.trimStart()),r=""),r+=e}),t.push(0===t.length?r:r.trimStart()),t.forEach((e,s)=>console.info(0===s?e:" ".repeat(29)+e))}})})}function r(e){e=e.replace(/\s+$/m,"").replace(/"/g,'""'),"darwin"===process.platform?s(`printf "${e}" | pbcopy`):"linux"===process.platform?s(`printf "${e}" | xclip -selection clipboard`):"win32"===process.platform&&s(`Set-Clipboard -Value "${e}"`,{shell:"powershell"})}}
2
+ const g=require("crypto")["randomInt"],r=require("child_process")["execSync"],m={lower:"abcdefghijklmnopqrstuvwxyz",upper:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",numbers:"0123456789",symbols:"!@#$%^&*()-_=+[]{}/\\|;:'\",.<>?"};function p(o={}){var e={verbose:!0,length:8,qty:1,charset:"",exclude:"",numbers:!1,symbols:!1,lowercase:!0,uppercase:!0,strict:!1};o={...e,...o};for(const r of Object.keys(o))if(!Object.prototype.hasOwnProperty.call(e,r))return console.error(`generatePassword() » ERROR: \`${r}\` is an invalid option.
3
+ `+`generatePassword() » Valid options:
4
+ [ ${Object.keys(e).join(", ")} ]`);for(const s of["length","qty"])if(o[s]=parseInt(o[s],10),isNaN(o[s])||o[s]<1)return console.error(`generatePassword() » ERROR: [${s}] option can only be an integer > 0.`);for(const i of["numbers","symbols","lowercase","uppercase","strict"])if("boolean"!=typeof o[i])return console.error(`generatePassword() » ERROR: [${i}] option can only be \`true\` or \`false\`.`);if(1<o.qty){const{qty:l,...c}=o;return d(l,c)}{var t,n="generatePasswords"===p.caller.name;o.verbose&&!n&&console.info("generatePassword() » Initializing character set...");let r=o.charset||(o.numbers?m.numbers:"")+(o.symbols?m.symbols:"")+(o.lowercase?m.lower:"")+(o.uppercase?m.upper:""),s=(""===r&&(r=m.lower+m.upper),o.exclude&&(o.verbose&&!n&&console.info("generatePassword() » Removing excluded characters..."),r=r.replace(new RegExp(`[${o.exclude}]`,"g"),"")),o.verbose&&!n&&console.info("generatePassword() » Generating password..."),"");for(let e=0;e<o.length;e++){var a=g(0,r.length);s+=r.charAt(a)}return o.strict&&(o.verbose&&!n&&console.info("generatePassword() » Enforcing strict mode..."),t=["number","symbol","lower","upper"].filter(e=>o[e+"s"]||o[e+"case"]),s=f(s,t)),o.verbose&&!n&&console.info("generatePassword() » Password generated!"+(require.main!==module?"\ngeneratePassword() » Check returned string.":"")),s}}function d(r,s={}){var e={verbose:!0,length:8,charset:"",exclude:"",numbers:!1,symbols:!1,lowercase:!0,uppercase:!0,strict:!1};if(s={...e,...s},r=parseInt(r,10),isNaN(r)||r<1)return console.error("generatePasswords() » ERROR: 1st arg <qty> can only be an integer > 0.");for(const t of Object.keys(s))if(!Object.prototype.hasOwnProperty.call(e,t))return console.error(`generatePasswords() » ERROR: \`${t}\` is an invalid option.
5
+ `+`generatePasswords() » Valid options:
6
+ [ ${Object.keys(e).join(", ")} ]`);if(s.length=parseInt(s.length),isNaN(s.length)||s.length<1)return console.error("generatePasswords() » ERROR: [length] option can only be an integer > 0.");for(const n of["numbers","symbols","lowercase","uppercase","strict"])if("boolean"!=typeof s[n])return console.error(`generatePasswords() » ERROR: [${n}] option can only be \`true\` or \`false\`.`);s.verbose&&console.info(`generatePasswords() » Generating password${1<r?"s":""}...`);var o=[];for(let e=0;e<r;e++)o.push(p(s));return s.verbose&&console.info(`generatePasswords() » Password${1<r?"s":""} generated!`+(require.main!==module?"\ngeneratePasswords() » Check returned array.":"")),o}function f(r,s=["number","symbol","lower","upper"],e={}){var o={verbose:!0};if(e={...o,...e},"string"!=typeof r)return console.error("strictify() » ERROR: 1st arg <password> must be a string.");var t=["number","symbol","lower","upper"];for(const p of s)if(!t.includes(p))return console.error(`strictify() » ERROR: \`${p}\` is an invalid character type.
7
+ `+`strictify() » Valid character types: [ ${t.join(", ")} ]`);for(const d of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(o,d))return console.error(`strictify() » ERROR: \`${d}\` is an invalid option.
8
+ `+`strictify() » Valid options: [ ${Object.keys(o).join(", ")} ]`);if("boolean"!=typeof e[d])return console.error(`strictify() » ERROR: [${d}] option can only be set to \`true\` or \`false\`.`)}for(const f of s)global["has"+f.charAt(0).toUpperCase()+f.slice(1)]=!1;for(let e=0;e<r.length;e++)for(const u of s)(m[u]||m[u+"s"]).includes(r.charAt(e))&&(global["has"+u.charAt(0).toUpperCase()+u.slice(1)]=!0);e.verbose&&console.info("strictify() » Strictifying password...");var n=Math.min(r.length,s.length),a=[];let i=0,l=r;for(const h of s)if(i<n&&!global["has"+h.charAt(0).toUpperCase()+h.slice(1)]){let e;for(;e=g(0,r.length),a.includes(e););a.push(e);var c=m[h]||m[h+"s"];l=l.substring(0,e)+c.charAt(g(0,c.length))+l.substring(e+1),i++}return e.verbose&&(0<i?console.info("strictify() » Password is now strict!\nstrictify() » Check returned string."):console.info(`strictify() » Password already includes ${s.join(" + ")} characters!
9
+ `+"strictify() » No modifications made.")),l}function e(e,r={}){var s={minLength:8,minLower:1,minUpper:1,minNumber:1,minSymbol:1},o={verbose:!0};if(r={...o,...r},"string"!=typeof e)return console.error("validateStrength() » ERROR: 1st arg <password> must be a string.");for(const i of Object.keys(r)){if(!Object.prototype.hasOwnProperty.call(o,i))return console.error(`validateStrength() » ERROR: \`${i}\` is an invalid option.
10
+ `+`validateStrength() » Valid options: [ ${Object.keys(o).join(", ")} ]`);if("boolean"!=typeof r[i])return console.error(`validateStrength() » ERROR: [${i}] option can only be set to \`true\` or \`false\`.`)}r.verbose&&console.info("validateStrength() » Validating password strength...");var t={lower:0,upper:0,number:0,symbol:0};for(const l of e)for(const c of Object.keys(t))(m[c]||m[c+"s"]).includes(l)&&t[c]++;var n=[];e.length<s.minLength&&n.push(`Make it at least ${s.minLength} characters long.`);for(const p of Object.keys(t))t[p]<s["min"+p.charAt(0).toUpperCase()+p.slice(1)]&&n.push("Include at least one "+p+`${["upper","lower"].includes(p)?"case letter":""}.`);let a=0;a+=e.length>=s.minLength?20:0;for(const d of Object.keys(t))a+=t[d]>=s["min"+d.charAt(0).toUpperCase()+d.slice(1)]?20:0;return r.verbose&&console.info("validateStrength() » Password strength validated!\n"+(require.main!==module?"validateStrength() » Check returned object for score/recommendations.":"")),{strengthScore:a,recommendations:n,isGood:80<=a}}if(require.main!==module)module.exports={generatePassword:p,generatePasswords:d,strictify:f,validateStrength:e};else{const n="",a="",i="",l={},c={paramOptions:{length:/^--?length/,qty:/^--?qu?a?n?ti?t?y=.*$/,charset:/^--?chars/,excludeChars:/^--?exclude=/},flags:{includeNums:/^--?(?:n|(?:include-?)?num(?:ber)?s?=?(?:true|1)?)$/,includeSymbols:/^--?(?:s|(?:include-?)?symbols?=?(?:true|1)?)$/,excludeLowerChars:/^--?(?:L|(?:exclude|disable|no)-?lower-?(?:case)?|lower-?(?:case)?=(?:false|0))$/,excludeUpperChars:/^--?(?:U|(?:exclude|disable|no)-?upper-?(?:case)?|upper-?(?:case)?=(?:false|0))$/,strictMode:/^--?s(?:trict)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(r=>{var e,s,o;r.startsWith("-")&&(e=Object.keys(c.paramOptions).find(e=>c.paramOptions[e].test(r)),o=Object.keys(c.flags).find(e=>c.flags[e].test(r)),s=Object.keys(c.infoCmds).find(e=>c.infoCmds[e].test(r)),o?l[o]=!0:e?(o=r.split("=")[1],l[e]=parseInt(o)||o):s||(console.error(`
11
+ ${a}ERROR: Arg [${r}] not recognized.`+n),console.info(`
12
+ ${i}Valid arguments are below.`+n),t(["paramOptions","flags","infoCmds"]),process.exit(1)))}),process.argv.some(e=>c.infoCmds.help.test(e)))t();else if(process.argv.some(e=>c.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{for(const h of["length","qty"])l[h]&&(isNaN(l[h])||l[h]<1)&&(console.error(`
13
+ ${a}Error: [${h}] argument can only be > 0.`+n),process.exit(1));const o={length:l.length||8,qty:l.qty||1,charset:l.charset,exclude:l.excludeChars,numbers:!!l.includeNums,symbols:!!l.includeSymbols,lowercase:!l.excludeLowerChars,uppercase:!l.excludeUpperChars,strict:!!l.strictMode},u=p(o);s(Array.isArray(u)?u.join("\n"):u)}function t(e=["cmdFormat","paramOptions","flags","infoCmds"]){const r={cmdFormat:[`
14
+ ${i}generate-pw [options|commands]`+n],paramOptions:["\nParameter options:"," --length=n Generate password(s) of n length."," --qty=n Generate n password(s)."," --charset=chars Only include chars in password(s)."," --charset=chars Only include chars in password(s)."," --exclude=chars Exclude chars from password(s)."],flags:["\nBoolean options:"," -n, --include-numbers Allow numbers in password(s)."," -s, --include-symbols Allow symbols in password(s)."," -L, --no-lowercase Disallow lowercase letters in password(s)."," -U, --no-uppercase Disallow uppercase letters in password(s)."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{r[e]?.forEach(e=>{{const o=process.stdout.columns||80,t=[],r=e.match(/\S+|\s+/g);let s="";r.forEach(e=>{var r=o-(0===t.length?0:29);s.length+e.length>r&&(t.push(0===t.length?s:s.trimStart()),s=""),s+=e}),t.push(0===t.length?s:s.trimStart()),t.forEach((e,r)=>console.info(0===r?e:" ".repeat(29)+e))}})})}function s(e){e=e.replace(/\s+$/m,"").replace(/"/g,'""'),"darwin"===process.platform?r(`printf "${e}" | pbcopy`):"linux"===process.platform?r(`printf "${e}" | xclip -selection clipboard`):"win32"===process.platform&&r(`Set-Clipboard -Value "${e}"`,{shell:"powershell"})}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generate-pw",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "Randomly generate cryptographically-secure passwords.",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -49,6 +49,6 @@
49
49
  "url": "https://github.com/sponsors/adamlui"
50
50
  },
51
51
  "devDependencies": {
52
- "@adamlui/minify.js": "^1.4.6"
52
+ "@adamlui/minify.js": "^1.4.7"
53
53
  }
54
54
  }