-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 938 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-disable no-useless-escape */
'use strict'
module.exports = (input) => {
let exp = '^(?=.*[a-z])'
// If uppercase set to false, it is possible, but not necessary
if (!(input && input.uppercase === false)) {
exp += '(?=.*[A-Z])'
}
// If numeric set to false, numbers are possible, but not necessary
if (!(input && input.numeric === false)) {
exp += '(?=.*[0-9])'
}
// If defined symbols, it is necessary
if (input && input.symbols) {
exp += '(?=.[!@#\$%\^&])'
}
// Min length of password is 8 by default of defined by input
let min = 8
if (input && input.min) {
min = input.min
}
// Max length of password is 32 by default of defined by input
let max = 32
if (input && input.max) {
if (input.max >= min) { // Max should not be more than min
max = input.max
} else {
max = min
}
}
exp += '.{' + min + ',' + max + '}$'
return new RegExp(exp)
}