revdev 0.43.0 → 0.44.0
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/lib/utils/regex.d.ts +5 -3
- package/lib/utils/regex.js +13 -6
- package/lib/utils/tests/slug.test.js +21 -0
- package/package.json +1 -1
package/lib/utils/regex.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ export declare class RegexUtil {
|
|
|
3
3
|
private static usernameRegex;
|
|
4
4
|
private static tagCodeRegex;
|
|
5
5
|
private static emailRegex;
|
|
6
|
+
private static passwordRegex;
|
|
6
7
|
static slug(slug: string): boolean;
|
|
7
|
-
static username(
|
|
8
|
-
static tagCode(
|
|
9
|
-
static email(
|
|
8
|
+
static username(text: string): boolean;
|
|
9
|
+
static tagCode(text: string): boolean;
|
|
10
|
+
static email(text: string): boolean;
|
|
11
|
+
static password(text: string): boolean;
|
|
10
12
|
}
|
package/lib/utils/regex.js
CHANGED
|
@@ -8,17 +8,23 @@ var RegexUtil = /** @class */ (function () {
|
|
|
8
8
|
this.slugRegex.lastIndex = 0;
|
|
9
9
|
return this.slugRegex.test(slug);
|
|
10
10
|
};
|
|
11
|
-
RegexUtil.username = function (
|
|
11
|
+
RegexUtil.username = function (text) {
|
|
12
12
|
this.usernameRegex.lastIndex = 0;
|
|
13
|
-
return this.usernameRegex.test(
|
|
13
|
+
return this.usernameRegex.test(text);
|
|
14
14
|
};
|
|
15
|
-
RegexUtil.tagCode = function (
|
|
15
|
+
RegexUtil.tagCode = function (text) {
|
|
16
16
|
this.tagCodeRegex.lastIndex = 0;
|
|
17
|
-
return this.tagCodeRegex.test(
|
|
17
|
+
return this.tagCodeRegex.test(text);
|
|
18
18
|
};
|
|
19
|
-
RegexUtil.email = function (
|
|
19
|
+
RegexUtil.email = function (text) {
|
|
20
20
|
this.emailRegex.lastIndex = 0;
|
|
21
|
-
return this.emailRegex.test(
|
|
21
|
+
return this.emailRegex.test(text);
|
|
22
|
+
};
|
|
23
|
+
// Minimum eight characters, at least one letter, one number and one special character:
|
|
24
|
+
// https://stackoverflow.com/a/21456918/721704
|
|
25
|
+
RegexUtil.password = function (text) {
|
|
26
|
+
this.passwordRegex.lastIndex = 0;
|
|
27
|
+
return this.passwordRegex.test(text);
|
|
22
28
|
};
|
|
23
29
|
// min: 6, max: 50
|
|
24
30
|
RegexUtil.slugRegex = /^[a-z][a-z0-9\-]{4,48}[a-z0-9]$/g;
|
|
@@ -26,6 +32,7 @@ var RegexUtil = /** @class */ (function () {
|
|
|
26
32
|
RegexUtil.usernameRegex = /^[a-z][a-z0-9]{5,48}$/g;
|
|
27
33
|
RegexUtil.tagCodeRegex = /^[a-z]([\-]?[a-z]+)*$/g;
|
|
28
34
|
RegexUtil.emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
35
|
+
RegexUtil.passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
|
|
29
36
|
return RegexUtil;
|
|
30
37
|
}());
|
|
31
38
|
exports.RegexUtil = RegexUtil;
|
|
@@ -68,4 +68,25 @@ describe("RegexUtil", function () {
|
|
|
68
68
|
validate("test@test.", false);
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
|
+
describe("password", function () {
|
|
72
|
+
// Minimum eight characters, at least one letter, one number and one special character:
|
|
73
|
+
function validate(text, valid) {
|
|
74
|
+
if (valid === void 0) { valid = true; }
|
|
75
|
+
expect(regex_1.RegexUtil.password(text)).toBe(valid);
|
|
76
|
+
}
|
|
77
|
+
test("true", function () {
|
|
78
|
+
validate("Alfaschool1!");
|
|
79
|
+
});
|
|
80
|
+
test("false", function () {
|
|
81
|
+
validate("alfaschool", false);
|
|
82
|
+
validate("Alfaschool", false);
|
|
83
|
+
validate("alfaschool1", false);
|
|
84
|
+
validate("alfaschool#", false);
|
|
85
|
+
//
|
|
86
|
+
validate("Alfas1!", false);
|
|
87
|
+
validate("Alfaschool1", false);
|
|
88
|
+
validate("Alfaschool!", false);
|
|
89
|
+
validate("alfaschool1!", false);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
71
92
|
});
|