@carecard/validate 2.0.3 → 2.0.5
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/validate.js +10 -2
- package/lib/validateProperties.js +101 -95
- package/package.json +1 -1
package/lib/validate.js
CHANGED
|
@@ -65,7 +65,7 @@ const isPasswordString = password => {
|
|
|
65
65
|
|
|
66
66
|
const isSimplePasswordString = password => {
|
|
67
67
|
if (password === undefined || typeof password !== "string" || password.length === 0) return false;
|
|
68
|
-
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{
|
|
68
|
+
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{8,24}$/;
|
|
69
69
|
return regExPassword.test(String(password));
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -161,6 +161,13 @@ const isCountryCodeString = (str) => {
|
|
|
161
161
|
return postalCodeRegex.test(str);
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
+
const isValidDomainName = (domain) => {
|
|
165
|
+
if (domain === undefined || typeof domain !== "string" || domain.length === 0 || domain.length > 253) return false;
|
|
166
|
+
|
|
167
|
+
const domainRegex = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/i;
|
|
168
|
+
return domainRegex.test(domain);
|
|
169
|
+
};
|
|
170
|
+
|
|
164
171
|
module.exports = {
|
|
165
172
|
isImageUrl,
|
|
166
173
|
isInteger,
|
|
@@ -186,5 +193,6 @@ module.exports = {
|
|
|
186
193
|
isPostalCodeString,
|
|
187
194
|
isSafeString,
|
|
188
195
|
isInStringArray,
|
|
189
|
-
isCountryCodeString
|
|
196
|
+
isCountryCodeString,
|
|
197
|
+
isValidDomainName
|
|
190
198
|
};
|
|
@@ -1,106 +1,112 @@
|
|
|
1
1
|
// Validate the property values format.
|
|
2
2
|
const {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
isEmailString,
|
|
4
|
+
isPhoneNumber,
|
|
5
|
+
isUrlSafeString,
|
|
6
|
+
isValidUuidString,
|
|
7
|
+
isSimplePasswordString,
|
|
8
|
+
isPasswordString,
|
|
9
|
+
isNameString,
|
|
10
|
+
isSafeSearchString,
|
|
11
|
+
isCharactersString,
|
|
12
|
+
isValidIntegerString,
|
|
13
|
+
isValidJsonString,
|
|
14
|
+
isImageUrl,
|
|
15
|
+
isValidDomainName,
|
|
16
|
+
} = require('./validate');
|
|
16
17
|
|
|
17
|
-
function validateProperties(
|
|
18
|
-
|
|
18
|
+
function validateProperties(obj) {
|
|
19
|
+
let returnObj = {};
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
for (let [key, value] of Object.entries(obj || {})) {
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
23
|
+
switch (key) {
|
|
24
|
+
case 'first_name' :
|
|
25
|
+
case 'username' :
|
|
26
|
+
case 'newStatus':
|
|
27
|
+
case 'description':
|
|
28
|
+
case 'comment':
|
|
29
|
+
case 'status':
|
|
30
|
+
case 'name':
|
|
31
|
+
case 'title' :
|
|
32
|
+
case 'brand':
|
|
33
|
+
case 'short_description' :
|
|
34
|
+
isNameString(value) ?
|
|
35
|
+
returnObj[key] = value : null;
|
|
36
|
+
break;
|
|
37
|
+
case 'search_string':
|
|
38
|
+
case 'searchString':
|
|
39
|
+
isSafeSearchString(value) ?
|
|
40
|
+
returnObj[key] = value : null;
|
|
41
|
+
break;
|
|
42
|
+
case 'password' :
|
|
43
|
+
case 'new_password' :
|
|
44
|
+
isSimplePasswordString(value) ?
|
|
45
|
+
returnObj[key] = value : null;
|
|
46
|
+
break;
|
|
47
|
+
case 'strong_password' :
|
|
48
|
+
isPasswordString(value) ?
|
|
49
|
+
returnObj[key] = value : null;
|
|
50
|
+
break;
|
|
51
|
+
case 'email' :
|
|
52
|
+
isEmailString(value) ?
|
|
53
|
+
returnObj[key] = value : null;
|
|
54
|
+
break;
|
|
55
|
+
case 'phone_number':
|
|
56
|
+
isPhoneNumber(value) ?
|
|
57
|
+
returnObj[key] = value : null;
|
|
58
|
+
break;
|
|
59
|
+
case 'token':
|
|
60
|
+
case 'email_confirm_token':
|
|
61
|
+
case 'verification_token':
|
|
62
|
+
isUrlSafeString(value) ?
|
|
63
|
+
returnObj[key] = value : null;
|
|
64
|
+
break;
|
|
65
|
+
case 'uuid':
|
|
66
|
+
case 'item_id':
|
|
67
|
+
case 'user_id':
|
|
68
|
+
case 'userId':
|
|
69
|
+
case 'image_id':
|
|
70
|
+
case 'itemId':
|
|
71
|
+
case 'orderId':
|
|
72
|
+
case 'category_id':
|
|
73
|
+
case 'parent_id':
|
|
74
|
+
isValidUuidString(value) ?
|
|
75
|
+
returnObj[key] = value : null;
|
|
76
|
+
break;
|
|
77
|
+
case 'period':
|
|
78
|
+
isCharactersString(value) ?
|
|
79
|
+
returnObj[key] = value : null;
|
|
80
|
+
break;
|
|
81
|
+
case 'offset_number':
|
|
82
|
+
case 'number_of_orders':
|
|
83
|
+
case 'price':
|
|
84
|
+
isValidIntegerString(value) ?
|
|
85
|
+
returnObj[key] = value : null;
|
|
86
|
+
break;
|
|
87
|
+
case 'about':
|
|
88
|
+
isValidJsonString(value) ? returnObj[key] = value.trim() : null;
|
|
89
|
+
break;
|
|
90
|
+
case 'weight':
|
|
91
|
+
case 'dimensions':
|
|
92
|
+
case 'permission':
|
|
93
|
+
isValidJsonString(JSON.stringify(value)) ? returnObj[key] = value : null;
|
|
94
|
+
break;
|
|
95
|
+
case 'image_url':
|
|
96
|
+
isImageUrl(value) ? returnObj[key] = value : null;
|
|
97
|
+
break;
|
|
98
|
+
case 'domain_name':
|
|
99
|
+
case 'domain':
|
|
100
|
+
case 'email_domain':
|
|
101
|
+
case 'email_domain_name':
|
|
102
|
+
isValidDomainName(value) ? returnObj[key] = value : null;
|
|
103
|
+
break;
|
|
99
104
|
}
|
|
105
|
+
}
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
return returnObj;
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
module.exports = {
|
|
105
|
-
|
|
111
|
+
validateProperties,
|
|
106
112
|
};
|