| 34 | |
| 35 | // Generate new password |
| 36 | const generatePassword = (lower, upper, number, symbol, length) => { |
| 37 | let newPassword = ""; |
| 38 | const typesCount = lower + upper + number + symbol; |
| 39 | const typesArr = [{ lower }, { upper }, { number }, { symbol }].filter( |
| 40 | (item) => Object.values(item)[0] |
| 41 | ); |
| 42 | |
| 43 | if (typesCount === 0 || length > 20) { |
| 44 | return ""; |
| 45 | } |
| 46 | |
| 47 | for (let i = 0; i < length; i += typesCount) { |
| 48 | typesArr.forEach((type) => { |
| 49 | const funcName = Object.keys(type)[0]; |
| 50 | newPassword += randomFunc[funcName](); |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | const finalPassword = newPassword.slice(0, length); |
| 55 | return finalPassword; |
| 56 | }; |
| 57 | |
| 58 | // Copy password to clipboard |
| 59 | copyToClipboardBtn.addEventListener("click", () => { |