1- const resultEl = document . getElementById ( "result" ) ;
2- const lengthEl = document . getElementById ( "length" ) ;
3- const uppercaseEl = document . getElementById ( "uppercase" ) ;
4- const lowercaseEl = document . getElementById ( "lowercase" ) ;
5- const numbersEl = document . getElementById ( "numbers" ) ;
6- const symbolsEl = document . getElementById ( "symbols" ) ;
7- const generateEl = document . getElementById ( "generate" ) ;
8- const clipboardEl = document . getElementById ( "clipboard" ) ;
1+ /* eslint-disable no-loop-func */
2+ const resultEl = document . getElementById ( 'result' ) ;
3+ const lengthEl = document . getElementById ( 'length' ) ;
4+ const uppercaseEl = document . getElementById ( 'uppercase' ) ;
5+ const lowercaseEl = document . getElementById ( 'lowercase' ) ;
6+ const numbersEl = document . getElementById ( 'numbers' ) ;
7+ const symbolsEl = document . getElementById ( 'symbols' ) ;
8+ const generateEl = document . getElementById ( 'generate' ) ;
9+ const clipboardEl = document . getElementById ( 'clipboard' ) ;
910
10- const randomFunc = {
11- lower : getRandomLower ,
12- upper : getRandomUpper ,
13- number : getRandomNumber ,
14- symbol : getRandomSymbol ,
15- } ;
16-
17- clipboardEl . addEventListener ( "click" , ( ) => {
18- const textarea = document . createElement ( "textarea" ) ;
11+ clipboardEl . addEventListener ( 'click' , ( ) => {
12+ const textarea = document . createElement ( 'textarea' ) ;
1913 const password = resultEl . innerText ;
2014
2115 if ( ! password ) {
@@ -25,36 +19,43 @@ clipboardEl.addEventListener("click", () => {
2519 textarea . value = password ;
2620 document . body . appendChild ( textarea ) ;
2721 textarea . select ( ) ;
28- document . execCommand ( " copy" ) ;
22+ document . execCommand ( ' copy' ) ;
2923 textarea . remove ( ) ;
30- alert ( " Password copied to clipboard!" ) ;
24+ alert ( ' Password copied to clipboard!' ) ;
3125} ) ;
3226
33- generateEl . addEventListener ( "click" , ( ) => {
34- const length = + lengthEl . value ;
35- const hasLower = lowercaseEl . checked ;
36- const hasUpper = uppercaseEl . checked ;
37- const hasNumber = numbersEl . checked ;
38- const hasSymbol = symbolsEl . checked ;
27+ function getRandomLower ( ) {
28+ return String . fromCharCode ( Math . floor ( Math . random ( ) * 26 ) + 97 ) ;
29+ }
3930
40- resultEl . innerText = generatePassword (
41- hasLower ,
42- hasUpper ,
43- hasNumber ,
44- hasSymbol ,
45- length
46- ) ;
47- } ) ;
31+ function getRandomUpper ( ) {
32+ return String . fromCharCode ( Math . floor ( Math . random ( ) * 26 ) + 65 ) ;
33+ }
34+
35+ function getRandomNumber ( ) {
36+ return String . fromCharCode ( Math . floor ( Math . random ( ) * 10 ) + 48 ) ;
37+ }
38+
39+ function getRandomSymbol ( ) {
40+ const symbols = '!@#$%^&*(){}[]=<>/,.' ;
41+ return symbols [ Math . floor ( Math . random ( ) * symbols . length ) ] ;
42+ }
4843
44+ const randomFunc = {
45+ lower : getRandomLower ,
46+ upper : getRandomUpper ,
47+ number : getRandomNumber ,
48+ symbol : getRandomSymbol ,
49+ } ;
4950function generatePassword ( lower , upper , number , symbol , length ) {
50- let generatedPassword = "" ;
51+ let generatedPassword = '' ;
5152 const typesCount = lower + upper + number + symbol ;
5253 const typesArr = [ { lower } , { upper } , { number } , { symbol } ] . filter (
53- ( item ) => Object . values ( item ) [ 0 ]
54+ ( item ) => Object . values ( item ) [ 0 ] ,
5455 ) ;
5556
5657 if ( typesCount === 0 ) {
57- return "" ;
58+ return '' ;
5859 }
5960
6061 for ( let i = 0 ; i < length ; i += typesCount ) {
@@ -68,20 +69,18 @@ function generatePassword(lower, upper, number, symbol, length) {
6869
6970 return finalPassword ;
7071}
72+ generateEl . addEventListener ( 'click' , ( ) => {
73+ const length = + lengthEl . value ;
74+ const hasLower = lowercaseEl . checked ;
75+ const hasUpper = uppercaseEl . checked ;
76+ const hasNumber = numbersEl . checked ;
77+ const hasSymbol = symbolsEl . checked ;
7178
72- function getRandomLower ( ) {
73- return String . fromCharCode ( Math . floor ( Math . random ( ) * 26 ) + 97 ) ;
74- }
75-
76- function getRandomUpper ( ) {
77- return String . fromCharCode ( Math . floor ( Math . random ( ) * 26 ) + 65 ) ;
78- }
79-
80- function getRandomNumber ( ) {
81- return String . fromCharCode ( Math . floor ( Math . random ( ) * 10 ) + 48 ) ;
82- }
83-
84- function getRandomSymbol ( ) {
85- const symbols = "!@#$%^&*(){}[]=<>/,." ;
86- return symbols [ Math . floor ( Math . random ( ) * symbols . length ) ] ;
87- }
79+ resultEl . innerText = generatePassword (
80+ hasLower ,
81+ hasUpper ,
82+ hasNumber ,
83+ hasSymbol ,
84+ length ,
85+ ) ;
86+ } ) ;
0 commit comments