@carecard/validate 2.2.2 → 2.2.3
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/dist/cjs/validate.cjs +32 -25
- package/dist/cjs/validateProperties.cjs +18 -0
- package/dist/esm/validate.js +32 -25
- package/dist/esm/validateProperties.js +18 -0
- package/package.json +1 -1
package/dist/cjs/validate.cjs
CHANGED
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isValidDomainName = exports.isCountryCodeString = exports.isInStringArray = exports.isSafeString = exports.isPostalCodeString = exports.isBoolValue = exports.isProvinceString = exports.isString6To16CharacterLong = exports.isString6To24CharacterLong = exports.isUrlSafeString = exports.isUsernameString = exports.isSimplePasswordStringFailureMessage = exports.isPasswordStringFailureMessage = exports.isSimplePasswordString = exports.isPasswordString = exports.isJwtString = exports.isEmailString = exports.isSafeSearchString = exports.isNameString = exports.isCharactersString = exports.isValidUuidString = exports.isValidIntegerString = exports.isValidJsonString = exports.isInteger = exports.isImageUrl = void 0;
|
|
4
4
|
exports.isPhoneNumber = isPhoneNumber;
|
|
5
5
|
const isImageUrl = (imageUrl) => {
|
|
6
|
-
if (imageUrl === undefined ||
|
|
6
|
+
if (imageUrl === undefined ||
|
|
7
|
+
typeof imageUrl !== 'string' ||
|
|
8
|
+
imageUrl.length === 0 ||
|
|
9
|
+
imageUrl.length > 2048)
|
|
7
10
|
return false;
|
|
8
11
|
const imageUrlRegex = /^[a-zA-Z0-9-_./]+$/;
|
|
9
12
|
return imageUrlRegex.test(imageUrl);
|
|
@@ -14,11 +17,11 @@ const isInteger = (number) => {
|
|
|
14
17
|
};
|
|
15
18
|
exports.isInteger = isInteger;
|
|
16
19
|
const isValidJsonString = (str) => {
|
|
17
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
20
|
+
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 10000)
|
|
18
21
|
return false;
|
|
19
22
|
try {
|
|
20
23
|
const json = JSON.parse(str);
|
|
21
|
-
return typeof json === 'object';
|
|
24
|
+
return typeof json === 'object' && json !== null;
|
|
22
25
|
}
|
|
23
26
|
catch {
|
|
24
27
|
return false;
|
|
@@ -26,9 +29,9 @@ const isValidJsonString = (str) => {
|
|
|
26
29
|
};
|
|
27
30
|
exports.isValidJsonString = isValidJsonString;
|
|
28
31
|
const isValidIntegerString = (str) => {
|
|
29
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
32
|
+
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 20)
|
|
30
33
|
return false;
|
|
31
|
-
return /^\d
|
|
34
|
+
return /^\d+$/.test(str);
|
|
32
35
|
};
|
|
33
36
|
exports.isValidIntegerString = isValidIntegerString;
|
|
34
37
|
const isValidUuidString = (str) => {
|
|
@@ -38,7 +41,7 @@ const isValidUuidString = (str) => {
|
|
|
38
41
|
};
|
|
39
42
|
exports.isValidUuidString = isValidUuidString;
|
|
40
43
|
const isCharactersString = (str) => {
|
|
41
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
44
|
+
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 1000)
|
|
42
45
|
return false;
|
|
43
46
|
return /^[\da-zA-Z _-]+$/.test(str);
|
|
44
47
|
};
|
|
@@ -57,29 +60,30 @@ const isSafeSearchString = (str) => {
|
|
|
57
60
|
};
|
|
58
61
|
exports.isSafeSearchString = isSafeSearchString;
|
|
59
62
|
const isEmailString = (email) => {
|
|
60
|
-
if (typeof email !== 'string' || email.length === 0 || email.length >
|
|
63
|
+
if (typeof email !== 'string' || email.length === 0 || email.length > 320) {
|
|
61
64
|
return false;
|
|
62
65
|
}
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
// Simplified safe email regex
|
|
67
|
+
const regExpEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-zA-Z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/;
|
|
68
|
+
return regExpEmail.test(email);
|
|
65
69
|
};
|
|
66
70
|
exports.isEmailString = isEmailString;
|
|
67
71
|
const isJwtString = (jwt) => {
|
|
68
|
-
if (typeof jwt !== 'string' || jwt ===
|
|
72
|
+
if (typeof jwt !== 'string' || jwt.length === 0 || jwt.length > 8192 || jwt.trim() === '')
|
|
69
73
|
return false;
|
|
70
74
|
const jwtRegex = /^eyJ[a-zA-Z0-9-_.]+$/;
|
|
71
75
|
return jwtRegex.test(jwt);
|
|
72
76
|
};
|
|
73
77
|
exports.isJwtString = isJwtString;
|
|
74
78
|
const isPasswordString = (password) => {
|
|
75
|
-
if (typeof password !== 'string' || password.length === 0)
|
|
79
|
+
if (typeof password !== 'string' || password.length === 0 || password.length > 128)
|
|
76
80
|
return false;
|
|
77
81
|
const regExPassword = /^(?=.*[a-zA-Z0-9])(?=.*[!@#$%^&*_-])[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
78
82
|
return regExPassword.test(String(password));
|
|
79
83
|
};
|
|
80
84
|
exports.isPasswordString = isPasswordString;
|
|
81
85
|
const isSimplePasswordString = (password) => {
|
|
82
|
-
if (typeof password !== 'string' || password.length === 0)
|
|
86
|
+
if (typeof password !== 'string' || password.length === 0 || password.length > 128)
|
|
83
87
|
return false;
|
|
84
88
|
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
85
89
|
return regExPassword.test(String(password));
|
|
@@ -95,7 +99,7 @@ const isPasswordStringFailureMessage = (password) => {
|
|
|
95
99
|
};
|
|
96
100
|
exports.isPasswordStringFailureMessage = isPasswordStringFailureMessage;
|
|
97
101
|
const isSimplePasswordStringFailureMessage = (password) => {
|
|
98
|
-
if (!(0, exports.
|
|
102
|
+
if (!(0, exports.isSimplePasswordString)(password)) {
|
|
99
103
|
return 'Total 6 to 32 characters, numbers or !@#$%^&*_-';
|
|
100
104
|
}
|
|
101
105
|
else {
|
|
@@ -110,15 +114,18 @@ const isUsernameString = (str) => {
|
|
|
110
114
|
};
|
|
111
115
|
exports.isUsernameString = isUsernameString;
|
|
112
116
|
function isPhoneNumber(str) {
|
|
113
|
-
if (typeof str !== 'string' || str.length === 0)
|
|
117
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 20)
|
|
114
118
|
return false;
|
|
115
119
|
return /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/.test(str);
|
|
116
120
|
}
|
|
117
121
|
const isUrlSafeString = (inputString) => {
|
|
118
|
-
if (typeof inputString !== 'string' ||
|
|
122
|
+
if (typeof inputString !== 'string' ||
|
|
123
|
+
inputString.length === 0 ||
|
|
124
|
+
inputString.length > 2048 ||
|
|
125
|
+
inputString.trim() === '')
|
|
119
126
|
return false;
|
|
120
|
-
const
|
|
121
|
-
return
|
|
127
|
+
const urlSafeRegex = /^[a-zA-Z0-9-_.]+$/;
|
|
128
|
+
return urlSafeRegex.test(inputString);
|
|
122
129
|
};
|
|
123
130
|
exports.isUrlSafeString = isUrlSafeString;
|
|
124
131
|
const isString6To24CharacterLong = (password) => {
|
|
@@ -136,41 +143,41 @@ exports.isString6To16CharacterLong = isString6To16CharacterLong;
|
|
|
136
143
|
const isProvinceString = (inputString) => {
|
|
137
144
|
const provinces = ['on', 'qc'];
|
|
138
145
|
if ((0, exports.isNameString)(inputString)) {
|
|
139
|
-
return provinces.includes(inputString.toLowerCase());
|
|
146
|
+
return provinces.includes(inputString.toLowerCase().trim());
|
|
140
147
|
}
|
|
141
148
|
return false;
|
|
142
149
|
};
|
|
143
150
|
exports.isProvinceString = isProvinceString;
|
|
144
151
|
const isBoolValue = (inputValue) => {
|
|
145
|
-
return
|
|
152
|
+
return typeof inputValue === 'boolean';
|
|
146
153
|
};
|
|
147
154
|
exports.isBoolValue = isBoolValue;
|
|
148
155
|
const isPostalCodeString = (inputString) => {
|
|
149
156
|
const postalCodeRegex = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$/i;
|
|
150
157
|
if ((0, exports.isNameString)(inputString)) {
|
|
151
|
-
return postalCodeRegex.test(inputString);
|
|
158
|
+
return postalCodeRegex.test(inputString.trim());
|
|
152
159
|
}
|
|
153
160
|
return false;
|
|
154
161
|
};
|
|
155
162
|
exports.isPostalCodeString = isPostalCodeString;
|
|
156
163
|
const isSafeString = (str) => {
|
|
157
|
-
if (typeof str !== 'string' || str.length === 0)
|
|
164
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 10000)
|
|
158
165
|
return false;
|
|
159
166
|
return /^[\da-zA-Z-_.,#*'()[\]: ]+$/.test(str);
|
|
160
167
|
};
|
|
161
168
|
exports.isSafeString = isSafeString;
|
|
162
169
|
const isInStringArray = (StringArray, inputString) => {
|
|
163
170
|
if ((0, exports.isNameString)(inputString)) {
|
|
164
|
-
return StringArray.includes(inputString.toLowerCase());
|
|
171
|
+
return StringArray.includes(inputString.toLowerCase().trim());
|
|
165
172
|
}
|
|
166
173
|
return false;
|
|
167
174
|
};
|
|
168
175
|
exports.isInStringArray = isInStringArray;
|
|
169
176
|
const isCountryCodeString = (str) => {
|
|
170
|
-
if (typeof str !== 'string' || str.length === 0)
|
|
177
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 4)
|
|
171
178
|
return false;
|
|
172
|
-
const
|
|
173
|
-
return
|
|
179
|
+
const countryCodeRegex = /^\+[1-9][0-9]{0,2}$/;
|
|
180
|
+
return countryCodeRegex.test(str);
|
|
174
181
|
};
|
|
175
182
|
exports.isCountryCodeString = isCountryCodeString;
|
|
176
183
|
const isValidDomainName = (domain) => {
|
|
@@ -8,7 +8,9 @@ function validateProperties(obj = {}) {
|
|
|
8
8
|
for (const [key, value] of Object.entries(obj || {})) {
|
|
9
9
|
switch (key) {
|
|
10
10
|
case 'first_name':
|
|
11
|
+
case 'firstName':
|
|
11
12
|
case 'username':
|
|
13
|
+
case 'new_status':
|
|
12
14
|
case 'newStatus':
|
|
13
15
|
case 'description':
|
|
14
16
|
case 'comment':
|
|
@@ -17,6 +19,7 @@ function validateProperties(obj = {}) {
|
|
|
17
19
|
case 'title':
|
|
18
20
|
case 'brand':
|
|
19
21
|
case 'short_description':
|
|
22
|
+
case 'shortDescription':
|
|
20
23
|
if ((0, validate_1.isNameString)(value)) {
|
|
21
24
|
returnObj[key] = value;
|
|
22
25
|
}
|
|
@@ -29,11 +32,13 @@ function validateProperties(obj = {}) {
|
|
|
29
32
|
break;
|
|
30
33
|
case 'password':
|
|
31
34
|
case 'new_password':
|
|
35
|
+
case 'newPassword':
|
|
32
36
|
if ((0, validate_1.isString6To16CharacterLong)(value) && (0, validate_1.isSimplePasswordString)(value)) {
|
|
33
37
|
returnObj[key] = value;
|
|
34
38
|
}
|
|
35
39
|
break;
|
|
36
40
|
case 'strong_password':
|
|
41
|
+
case 'strongPassword':
|
|
37
42
|
if ((0, validate_1.isString6To16CharacterLong)(value) && (0, validate_1.isPasswordString)(value)) {
|
|
38
43
|
returnObj[key] = value;
|
|
39
44
|
}
|
|
@@ -44,13 +49,16 @@ function validateProperties(obj = {}) {
|
|
|
44
49
|
}
|
|
45
50
|
break;
|
|
46
51
|
case 'phone_number':
|
|
52
|
+
case 'phoneNumber':
|
|
47
53
|
if ((0, validate_1.isPhoneNumber)(value)) {
|
|
48
54
|
returnObj[key] = value;
|
|
49
55
|
}
|
|
50
56
|
break;
|
|
51
57
|
case 'token':
|
|
52
58
|
case 'email_confirm_token':
|
|
59
|
+
case 'emailConfirmToken':
|
|
53
60
|
case 'verification_token':
|
|
61
|
+
case 'verificationToken':
|
|
54
62
|
if ((0, validate_1.isUrlSafeString)(value)) {
|
|
55
63
|
returnObj[key] = value;
|
|
56
64
|
}
|
|
@@ -61,9 +69,13 @@ function validateProperties(obj = {}) {
|
|
|
61
69
|
case 'image_id':
|
|
62
70
|
case 'itemId':
|
|
63
71
|
case 'userId':
|
|
72
|
+
case 'imageId':
|
|
73
|
+
case 'order_id':
|
|
64
74
|
case 'orderId':
|
|
65
75
|
case 'category_id':
|
|
76
|
+
case 'categoryId':
|
|
66
77
|
case 'parent_id':
|
|
78
|
+
case 'parentId':
|
|
67
79
|
if ((0, validate_1.isValidUuidString)(value)) {
|
|
68
80
|
returnObj[key] = value;
|
|
69
81
|
}
|
|
@@ -74,7 +86,9 @@ function validateProperties(obj = {}) {
|
|
|
74
86
|
}
|
|
75
87
|
break;
|
|
76
88
|
case 'offset_number':
|
|
89
|
+
case 'offsetNumber':
|
|
77
90
|
case 'number_of_orders':
|
|
91
|
+
case 'numberOfOrders':
|
|
78
92
|
case 'price':
|
|
79
93
|
if ((0, validate_1.isValidIntegerString)(value)) {
|
|
80
94
|
returnObj[key] = value;
|
|
@@ -93,14 +107,18 @@ function validateProperties(obj = {}) {
|
|
|
93
107
|
}
|
|
94
108
|
break;
|
|
95
109
|
case 'image_url':
|
|
110
|
+
case 'imageUrl':
|
|
96
111
|
if ((0, validate_1.isImageUrl)(value)) {
|
|
97
112
|
returnObj[key] = value;
|
|
98
113
|
}
|
|
99
114
|
break;
|
|
100
115
|
case 'domain_name':
|
|
116
|
+
case 'domainName':
|
|
101
117
|
case 'domain':
|
|
102
118
|
case 'email_domain':
|
|
119
|
+
case 'emailDomain':
|
|
103
120
|
case 'email_domain_name':
|
|
121
|
+
case 'emailDomainName':
|
|
104
122
|
if ((0, validate_1.isValidDomainName)(value)) {
|
|
105
123
|
returnObj[key] = value;
|
|
106
124
|
}
|
package/dist/esm/validate.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export const isImageUrl = (imageUrl) => {
|
|
2
|
-
if (imageUrl === undefined ||
|
|
2
|
+
if (imageUrl === undefined ||
|
|
3
|
+
typeof imageUrl !== 'string' ||
|
|
4
|
+
imageUrl.length === 0 ||
|
|
5
|
+
imageUrl.length > 2048)
|
|
3
6
|
return false;
|
|
4
7
|
const imageUrlRegex = /^[a-zA-Z0-9-_./]+$/;
|
|
5
8
|
return imageUrlRegex.test(imageUrl);
|
|
@@ -8,20 +11,20 @@ export const isInteger = (number) => {
|
|
|
8
11
|
return Number.isInteger(number);
|
|
9
12
|
};
|
|
10
13
|
export const isValidJsonString = (str) => {
|
|
11
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
14
|
+
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 10000)
|
|
12
15
|
return false;
|
|
13
16
|
try {
|
|
14
17
|
const json = JSON.parse(str);
|
|
15
|
-
return typeof json === 'object';
|
|
18
|
+
return typeof json === 'object' && json !== null;
|
|
16
19
|
}
|
|
17
20
|
catch {
|
|
18
21
|
return false;
|
|
19
22
|
}
|
|
20
23
|
};
|
|
21
24
|
export const isValidIntegerString = (str) => {
|
|
22
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
25
|
+
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 20)
|
|
23
26
|
return false;
|
|
24
|
-
return /^\d
|
|
27
|
+
return /^\d+$/.test(str);
|
|
25
28
|
};
|
|
26
29
|
export const isValidUuidString = (str) => {
|
|
27
30
|
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
@@ -29,7 +32,7 @@ export const isValidUuidString = (str) => {
|
|
|
29
32
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
|
|
30
33
|
};
|
|
31
34
|
export const isCharactersString = (str) => {
|
|
32
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
35
|
+
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 1000)
|
|
33
36
|
return false;
|
|
34
37
|
return /^[\da-zA-Z _-]+$/.test(str);
|
|
35
38
|
};
|
|
@@ -45,26 +48,27 @@ export const isSafeSearchString = (str) => {
|
|
|
45
48
|
return /^[A-Za-z][0-9a-zA-Z\-_.,'()@ ]{1,100}$/.test(str.trim());
|
|
46
49
|
};
|
|
47
50
|
export const isEmailString = (email) => {
|
|
48
|
-
if (typeof email !== 'string' || email.length === 0 || email.length >
|
|
51
|
+
if (typeof email !== 'string' || email.length === 0 || email.length > 320) {
|
|
49
52
|
return false;
|
|
50
53
|
}
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
// Simplified safe email regex
|
|
55
|
+
const regExpEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-zA-Z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/;
|
|
56
|
+
return regExpEmail.test(email);
|
|
53
57
|
};
|
|
54
58
|
export const isJwtString = (jwt) => {
|
|
55
|
-
if (typeof jwt !== 'string' || jwt ===
|
|
59
|
+
if (typeof jwt !== 'string' || jwt.length === 0 || jwt.length > 8192 || jwt.trim() === '')
|
|
56
60
|
return false;
|
|
57
61
|
const jwtRegex = /^eyJ[a-zA-Z0-9-_.]+$/;
|
|
58
62
|
return jwtRegex.test(jwt);
|
|
59
63
|
};
|
|
60
64
|
export const isPasswordString = (password) => {
|
|
61
|
-
if (typeof password !== 'string' || password.length === 0)
|
|
65
|
+
if (typeof password !== 'string' || password.length === 0 || password.length > 128)
|
|
62
66
|
return false;
|
|
63
67
|
const regExPassword = /^(?=.*[a-zA-Z0-9])(?=.*[!@#$%^&*_-])[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
64
68
|
return regExPassword.test(String(password));
|
|
65
69
|
};
|
|
66
70
|
export const isSimplePasswordString = (password) => {
|
|
67
|
-
if (typeof password !== 'string' || password.length === 0)
|
|
71
|
+
if (typeof password !== 'string' || password.length === 0 || password.length > 128)
|
|
68
72
|
return false;
|
|
69
73
|
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
70
74
|
return regExPassword.test(String(password));
|
|
@@ -78,7 +82,7 @@ export const isPasswordStringFailureMessage = (password) => {
|
|
|
78
82
|
}
|
|
79
83
|
};
|
|
80
84
|
export const isSimplePasswordStringFailureMessage = (password) => {
|
|
81
|
-
if (!
|
|
85
|
+
if (!isSimplePasswordString(password)) {
|
|
82
86
|
return 'Total 6 to 32 characters, numbers or !@#$%^&*_-';
|
|
83
87
|
}
|
|
84
88
|
else {
|
|
@@ -91,15 +95,18 @@ export const isUsernameString = (str) => {
|
|
|
91
95
|
return /^[0-9a-zA-Z]+$/.test(str);
|
|
92
96
|
};
|
|
93
97
|
export function isPhoneNumber(str) {
|
|
94
|
-
if (typeof str !== 'string' || str.length === 0)
|
|
98
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 20)
|
|
95
99
|
return false;
|
|
96
100
|
return /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/.test(str);
|
|
97
101
|
}
|
|
98
102
|
export const isUrlSafeString = (inputString) => {
|
|
99
|
-
if (typeof inputString !== 'string' ||
|
|
103
|
+
if (typeof inputString !== 'string' ||
|
|
104
|
+
inputString.length === 0 ||
|
|
105
|
+
inputString.length > 2048 ||
|
|
106
|
+
inputString.trim() === '')
|
|
100
107
|
return false;
|
|
101
|
-
const
|
|
102
|
-
return
|
|
108
|
+
const urlSafeRegex = /^[a-zA-Z0-9-_.]+$/;
|
|
109
|
+
return urlSafeRegex.test(inputString);
|
|
103
110
|
};
|
|
104
111
|
export const isString6To24CharacterLong = (password) => {
|
|
105
112
|
if (typeof password !== 'string' || password.length === 0)
|
|
@@ -114,36 +121,36 @@ export const isString6To16CharacterLong = (password) => {
|
|
|
114
121
|
export const isProvinceString = (inputString) => {
|
|
115
122
|
const provinces = ['on', 'qc'];
|
|
116
123
|
if (isNameString(inputString)) {
|
|
117
|
-
return provinces.includes(inputString.toLowerCase());
|
|
124
|
+
return provinces.includes(inputString.toLowerCase().trim());
|
|
118
125
|
}
|
|
119
126
|
return false;
|
|
120
127
|
};
|
|
121
128
|
export const isBoolValue = (inputValue) => {
|
|
122
|
-
return
|
|
129
|
+
return typeof inputValue === 'boolean';
|
|
123
130
|
};
|
|
124
131
|
export const isPostalCodeString = (inputString) => {
|
|
125
132
|
const postalCodeRegex = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$/i;
|
|
126
133
|
if (isNameString(inputString)) {
|
|
127
|
-
return postalCodeRegex.test(inputString);
|
|
134
|
+
return postalCodeRegex.test(inputString.trim());
|
|
128
135
|
}
|
|
129
136
|
return false;
|
|
130
137
|
};
|
|
131
138
|
export const isSafeString = (str) => {
|
|
132
|
-
if (typeof str !== 'string' || str.length === 0)
|
|
139
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 10000)
|
|
133
140
|
return false;
|
|
134
141
|
return /^[\da-zA-Z-_.,#*'()[\]: ]+$/.test(str);
|
|
135
142
|
};
|
|
136
143
|
export const isInStringArray = (StringArray, inputString) => {
|
|
137
144
|
if (isNameString(inputString)) {
|
|
138
|
-
return StringArray.includes(inputString.toLowerCase());
|
|
145
|
+
return StringArray.includes(inputString.toLowerCase().trim());
|
|
139
146
|
}
|
|
140
147
|
return false;
|
|
141
148
|
};
|
|
142
149
|
export const isCountryCodeString = (str) => {
|
|
143
|
-
if (typeof str !== 'string' || str.length === 0)
|
|
150
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 4)
|
|
144
151
|
return false;
|
|
145
|
-
const
|
|
146
|
-
return
|
|
152
|
+
const countryCodeRegex = /^\+[1-9][0-9]{0,2}$/;
|
|
153
|
+
return countryCodeRegex.test(str);
|
|
147
154
|
};
|
|
148
155
|
export const isValidDomainName = (domain) => {
|
|
149
156
|
if (typeof domain !== 'string' || domain.length === 0 || domain.length > 253)
|
|
@@ -5,7 +5,9 @@ export function validateProperties(obj = {}) {
|
|
|
5
5
|
for (const [key, value] of Object.entries(obj || {})) {
|
|
6
6
|
switch (key) {
|
|
7
7
|
case 'first_name':
|
|
8
|
+
case 'firstName':
|
|
8
9
|
case 'username':
|
|
10
|
+
case 'new_status':
|
|
9
11
|
case 'newStatus':
|
|
10
12
|
case 'description':
|
|
11
13
|
case 'comment':
|
|
@@ -14,6 +16,7 @@ export function validateProperties(obj = {}) {
|
|
|
14
16
|
case 'title':
|
|
15
17
|
case 'brand':
|
|
16
18
|
case 'short_description':
|
|
19
|
+
case 'shortDescription':
|
|
17
20
|
if (isNameString(value)) {
|
|
18
21
|
returnObj[key] = value;
|
|
19
22
|
}
|
|
@@ -26,11 +29,13 @@ export function validateProperties(obj = {}) {
|
|
|
26
29
|
break;
|
|
27
30
|
case 'password':
|
|
28
31
|
case 'new_password':
|
|
32
|
+
case 'newPassword':
|
|
29
33
|
if (isString6To16CharacterLong(value) && isSimplePasswordString(value)) {
|
|
30
34
|
returnObj[key] = value;
|
|
31
35
|
}
|
|
32
36
|
break;
|
|
33
37
|
case 'strong_password':
|
|
38
|
+
case 'strongPassword':
|
|
34
39
|
if (isString6To16CharacterLong(value) && isPasswordString(value)) {
|
|
35
40
|
returnObj[key] = value;
|
|
36
41
|
}
|
|
@@ -41,13 +46,16 @@ export function validateProperties(obj = {}) {
|
|
|
41
46
|
}
|
|
42
47
|
break;
|
|
43
48
|
case 'phone_number':
|
|
49
|
+
case 'phoneNumber':
|
|
44
50
|
if (isPhoneNumber(value)) {
|
|
45
51
|
returnObj[key] = value;
|
|
46
52
|
}
|
|
47
53
|
break;
|
|
48
54
|
case 'token':
|
|
49
55
|
case 'email_confirm_token':
|
|
56
|
+
case 'emailConfirmToken':
|
|
50
57
|
case 'verification_token':
|
|
58
|
+
case 'verificationToken':
|
|
51
59
|
if (isUrlSafeString(value)) {
|
|
52
60
|
returnObj[key] = value;
|
|
53
61
|
}
|
|
@@ -58,9 +66,13 @@ export function validateProperties(obj = {}) {
|
|
|
58
66
|
case 'image_id':
|
|
59
67
|
case 'itemId':
|
|
60
68
|
case 'userId':
|
|
69
|
+
case 'imageId':
|
|
70
|
+
case 'order_id':
|
|
61
71
|
case 'orderId':
|
|
62
72
|
case 'category_id':
|
|
73
|
+
case 'categoryId':
|
|
63
74
|
case 'parent_id':
|
|
75
|
+
case 'parentId':
|
|
64
76
|
if (isValidUuidString(value)) {
|
|
65
77
|
returnObj[key] = value;
|
|
66
78
|
}
|
|
@@ -71,7 +83,9 @@ export function validateProperties(obj = {}) {
|
|
|
71
83
|
}
|
|
72
84
|
break;
|
|
73
85
|
case 'offset_number':
|
|
86
|
+
case 'offsetNumber':
|
|
74
87
|
case 'number_of_orders':
|
|
88
|
+
case 'numberOfOrders':
|
|
75
89
|
case 'price':
|
|
76
90
|
if (isValidIntegerString(value)) {
|
|
77
91
|
returnObj[key] = value;
|
|
@@ -90,14 +104,18 @@ export function validateProperties(obj = {}) {
|
|
|
90
104
|
}
|
|
91
105
|
break;
|
|
92
106
|
case 'image_url':
|
|
107
|
+
case 'imageUrl':
|
|
93
108
|
if (isImageUrl(value)) {
|
|
94
109
|
returnObj[key] = value;
|
|
95
110
|
}
|
|
96
111
|
break;
|
|
97
112
|
case 'domain_name':
|
|
113
|
+
case 'domainName':
|
|
98
114
|
case 'domain':
|
|
99
115
|
case 'email_domain':
|
|
116
|
+
case 'emailDomain':
|
|
100
117
|
case 'email_domain_name':
|
|
118
|
+
case 'emailDomainName':
|
|
101
119
|
if (isValidDomainName(value)) {
|
|
102
120
|
returnObj[key] = value;
|
|
103
121
|
}
|