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' ) ;
9
10
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' ) ;
19
13
const password = resultEl . innerText ;
20
14
21
15
if ( ! password ) {
@@ -25,36 +19,43 @@ clipboardEl.addEventListener("click", () => {
25
19
textarea . value = password ;
26
20
document . body . appendChild ( textarea ) ;
27
21
textarea . select ( ) ;
28
- document . execCommand ( " copy" ) ;
22
+ document . execCommand ( ' copy' ) ;
29
23
textarea . remove ( ) ;
30
- alert ( " Password copied to clipboard!" ) ;
24
+ alert ( ' Password copied to clipboard!' ) ;
31
25
} ) ;
32
26
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
+ }
39
30
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
+ }
48
43
44
+ const randomFunc = {
45
+ lower : getRandomLower ,
46
+ upper : getRandomUpper ,
47
+ number : getRandomNumber ,
48
+ symbol : getRandomSymbol ,
49
+ } ;
49
50
function generatePassword ( lower , upper , number , symbol , length ) {
50
- let generatedPassword = "" ;
51
+ let generatedPassword = '' ;
51
52
const typesCount = lower + upper + number + symbol ;
52
53
const typesArr = [ { lower } , { upper } , { number } , { symbol } ] . filter (
53
- ( item ) => Object . values ( item ) [ 0 ]
54
+ ( item ) => Object . values ( item ) [ 0 ] ,
54
55
) ;
55
56
56
57
if ( typesCount === 0 ) {
57
- return "" ;
58
+ return '' ;
58
59
}
59
60
60
61
for ( let i = 0 ; i < length ; i += typesCount ) {
@@ -68,20 +69,18 @@ function generatePassword(lower, upper, number, symbol, length) {
68
69
69
70
return finalPassword ;
70
71
}
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 ;
71
78
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