@carecard/validate 2.2.4 → 2.2.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/index.js +4 -0
- package/{src → lib}/validate.js +56 -28
- package/{src → lib}/validateProperties.js +7 -3
- package/package.json +11 -38
- package/src/index.js +0 -2
package/index.js
ADDED
package/{src → lib}/validate.js
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const isImageUrl = (imageUrl) => {
|
|
2
2
|
if (
|
|
3
3
|
imageUrl === undefined ||
|
|
4
4
|
typeof imageUrl !== 'string' ||
|
|
@@ -11,11 +11,11 @@ export const isImageUrl = (imageUrl) => {
|
|
|
11
11
|
return imageUrlRegex.test(imageUrl);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const isInteger = (number) => {
|
|
15
15
|
return Number.isInteger(number);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const isValidJsonString = (str) => {
|
|
19
19
|
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 10000)
|
|
20
20
|
return false;
|
|
21
21
|
|
|
@@ -27,36 +27,36 @@ export const isValidJsonString = (str) => {
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const isValidIntegerString = (str) => {
|
|
31
31
|
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 20)
|
|
32
32
|
return false;
|
|
33
33
|
return /^\d+$/.test(str);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const isValidUuidString = (str) => {
|
|
37
37
|
if (str === undefined || typeof str !== 'string' || str.length === 0) return false;
|
|
38
38
|
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);
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const isCharactersString = (str) => {
|
|
42
42
|
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 1000)
|
|
43
43
|
return false;
|
|
44
44
|
return /^[\da-zA-Z _-]+$/.test(str);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const isNameString = (str) => {
|
|
48
48
|
if (typeof str !== 'string' || str.length === 0 || str.length > 1000) {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
51
|
return /^[A-Za-z][0-9a-zA-Z-_.,'() ]+$/.test(str.trim());
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const isSafeSearchString = (str) => {
|
|
55
55
|
if (typeof str !== 'string' || str.length === 0) return false;
|
|
56
56
|
return /^[A-Za-z][0-9a-zA-Z\-_.,'()@ ]{1,100}$/.test(str.trim());
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
const isEmailString = (email) => {
|
|
60
60
|
if (typeof email !== 'string' || email.length === 0 || email.length > 320) {
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
@@ -66,26 +66,26 @@ export const isEmailString = (email) => {
|
|
|
66
66
|
return regExpEmail.test(email);
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
const isJwtString = (jwt) => {
|
|
70
70
|
if (typeof jwt !== 'string' || jwt.length === 0 || jwt.length > 8192 || jwt.trim() === '')
|
|
71
71
|
return false;
|
|
72
72
|
const jwtRegex = /^eyJ[a-zA-Z0-9-_.]+$/;
|
|
73
73
|
return jwtRegex.test(jwt);
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
const isPasswordString = (password) => {
|
|
77
77
|
if (typeof password !== 'string' || password.length === 0 || password.length > 128) return false;
|
|
78
78
|
const regExPassword = /^(?=.*[a-zA-Z0-9])(?=.*[!@#$%^&*_-])[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
79
79
|
return regExPassword.test(String(password));
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const isSimplePasswordString = (password) => {
|
|
83
83
|
if (typeof password !== 'string' || password.length === 0 || password.length > 128) return false;
|
|
84
84
|
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
85
85
|
return regExPassword.test(String(password));
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
const isPasswordStringFailureMessage = (password) => {
|
|
89
89
|
if (!isPasswordString(password)) {
|
|
90
90
|
return 'Total 6 to 32 characters, numbers and one of !@#$%^&*_-';
|
|
91
91
|
} else {
|
|
@@ -93,7 +93,7 @@ export const isPasswordStringFailureMessage = (password) => {
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
const isSimplePasswordStringFailureMessage = (password) => {
|
|
97
97
|
if (!isSimplePasswordString(password)) {
|
|
98
98
|
return 'Total 6 to 32 characters, numbers or !@#$%^&*_-';
|
|
99
99
|
} else {
|
|
@@ -101,17 +101,17 @@ export const isSimplePasswordStringFailureMessage = (password) => {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
const isUsernameString = (str) => {
|
|
105
105
|
if (typeof str !== 'string' || str.length === 0 || str.length > 200) return false;
|
|
106
106
|
return /^[0-9a-zA-Z]+$/.test(str);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
function isPhoneNumber(str) {
|
|
110
110
|
if (typeof str !== 'string' || str.length === 0 || str.length > 20) return false;
|
|
111
111
|
return /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/.test(str);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
const isUrlSafeString = (inputString) => {
|
|
115
115
|
if (
|
|
116
116
|
typeof inputString !== 'string' ||
|
|
117
117
|
inputString.length === 0 ||
|
|
@@ -123,17 +123,17 @@ export const isUrlSafeString = (inputString) => {
|
|
|
123
123
|
return urlSafeRegex.test(inputString);
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
const isString6To24CharacterLong = (password) => {
|
|
127
127
|
if (typeof password !== 'string' || password.length === 0) return false;
|
|
128
128
|
return 6 <= password.length && password.length <= 24;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
const isString6To16CharacterLong = (password) => {
|
|
132
132
|
if (typeof password !== 'string' || password.length === 0) return false;
|
|
133
133
|
return 6 <= password.length && password.length <= 16;
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
const isProvinceString = (inputString) => {
|
|
137
137
|
const provinces = ['on', 'qc'];
|
|
138
138
|
|
|
139
139
|
if (isNameString(inputString)) {
|
|
@@ -143,11 +143,11 @@ export const isProvinceString = (inputString) => {
|
|
|
143
143
|
return false;
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
const isBoolValue = (inputValue) => {
|
|
147
147
|
return typeof inputValue === 'boolean';
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
const isPostalCodeString = (inputString) => {
|
|
151
151
|
const postalCodeRegex = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$/i;
|
|
152
152
|
|
|
153
153
|
if (isNameString(inputString)) {
|
|
@@ -157,12 +157,12 @@ export const isPostalCodeString = (inputString) => {
|
|
|
157
157
|
return false;
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
const isSafeString = (str) => {
|
|
161
161
|
if (typeof str !== 'string' || str.length === 0 || str.length > 10000) return false;
|
|
162
162
|
return /^[\da-zA-Z-_.,#*'()[\]: ]+$/.test(str);
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
const isInStringArray = (StringArray, inputString) => {
|
|
166
166
|
if (isNameString(inputString)) {
|
|
167
167
|
return StringArray.includes(inputString.toLowerCase().trim());
|
|
168
168
|
}
|
|
@@ -170,7 +170,7 @@ export const isInStringArray = (StringArray, inputString) => {
|
|
|
170
170
|
return false;
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
const isCountryCodeString = (str) => {
|
|
174
174
|
if (typeof str !== 'string' || str.length === 0 || str.length > 4) return false;
|
|
175
175
|
|
|
176
176
|
const countryCodeRegex = /^\+[1-9][0-9]{0,2}$/;
|
|
@@ -178,10 +178,38 @@ export const isCountryCodeString = (str) => {
|
|
|
178
178
|
return countryCodeRegex.test(str);
|
|
179
179
|
};
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
const isValidDomainName = (domain) => {
|
|
182
182
|
if (typeof domain !== 'string' || domain.length === 0 || domain.length > 253) return false;
|
|
183
183
|
|
|
184
|
-
const domainRegex =
|
|
185
|
-
/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/i;
|
|
184
|
+
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;
|
|
186
185
|
return domainRegex.test(domain);
|
|
187
186
|
};
|
|
187
|
+
|
|
188
|
+
module.exports = {
|
|
189
|
+
isImageUrl,
|
|
190
|
+
isInteger,
|
|
191
|
+
isValidJsonString,
|
|
192
|
+
isValidIntegerString,
|
|
193
|
+
isValidUuidString,
|
|
194
|
+
isCharactersString,
|
|
195
|
+
isNameString,
|
|
196
|
+
isSafeSearchString,
|
|
197
|
+
isEmailString,
|
|
198
|
+
isJwtString,
|
|
199
|
+
isPasswordString,
|
|
200
|
+
isSimplePasswordString,
|
|
201
|
+
isPasswordStringFailureMessage,
|
|
202
|
+
isSimplePasswordStringFailureMessage,
|
|
203
|
+
isUsernameString,
|
|
204
|
+
isPhoneNumber,
|
|
205
|
+
isUrlSafeString,
|
|
206
|
+
isString6To24CharacterLong,
|
|
207
|
+
isString6To16CharacterLong,
|
|
208
|
+
isProvinceString,
|
|
209
|
+
isBoolValue,
|
|
210
|
+
isPostalCodeString,
|
|
211
|
+
isSafeString,
|
|
212
|
+
isInStringArray,
|
|
213
|
+
isCountryCodeString,
|
|
214
|
+
isValidDomainName
|
|
215
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Validate the property values format.
|
|
2
|
-
|
|
2
|
+
const {
|
|
3
3
|
isEmailString,
|
|
4
4
|
isPhoneNumber,
|
|
5
5
|
isUrlSafeString,
|
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
isValidJsonString,
|
|
15
15
|
isImageUrl,
|
|
16
16
|
isValidDomainName,
|
|
17
|
-
}
|
|
17
|
+
} = require('./validate');
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
function validateProperties(obj = {}) {
|
|
20
20
|
const returnObj = {};
|
|
21
21
|
|
|
22
22
|
for (const [key, value] of Object.entries(obj || {})) {
|
|
@@ -142,3 +142,7 @@ export function validateProperties(obj = {}) {
|
|
|
142
142
|
|
|
143
143
|
return returnObj;
|
|
144
144
|
}
|
|
145
|
+
|
|
146
|
+
module.exports = {
|
|
147
|
+
validateProperties,
|
|
148
|
+
};
|
package/package.json
CHANGED
|
@@ -1,49 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carecard/validate",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"private": false,
|
|
5
|
-
"description": "Validate functions",
|
|
6
|
-
"license": "ISC",
|
|
7
|
-
"author": "PK Singh",
|
|
3
|
+
"version": "2.2.5",
|
|
8
4
|
"repository": {
|
|
9
5
|
"type": "git",
|
|
10
6
|
"url": "git+https://github.com/CareCard-ca/pkg-validate.git"
|
|
11
7
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"access": "public"
|
|
15
|
-
},
|
|
16
|
-
"main": "./src/index.js",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": "./src/index.js"
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"src"
|
|
22
|
-
],
|
|
8
|
+
"description": "Validate data",
|
|
9
|
+
"main": "index.js",
|
|
23
10
|
"scripts": {
|
|
24
|
-
"test": "
|
|
25
|
-
"format": "prettier --write .",
|
|
26
|
-
"format:check": "prettier --check .",
|
|
27
|
-
"lint": "eslint",
|
|
28
|
-
"lint:fix": "eslint --fix",
|
|
29
|
-
"prepare": "husky"
|
|
30
|
-
},
|
|
31
|
-
"lint-staged": {
|
|
32
|
-
"*.{js,cjs}": [
|
|
33
|
-
"eslint --fix",
|
|
34
|
-
"prettier --write"
|
|
35
|
-
],
|
|
36
|
-
"*.{json,md,yml}": [
|
|
37
|
-
"prettier --write"
|
|
38
|
-
]
|
|
11
|
+
"test": "export NODE_ENV=test && mocha --recursive"
|
|
39
12
|
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"validate",
|
|
15
|
+
"data"
|
|
16
|
+
],
|
|
17
|
+
"author": "CareCard team",
|
|
18
|
+
"license": "ISC",
|
|
40
19
|
"devDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"eslint": "9.39.2",
|
|
43
|
-
"globals": "^17.1.0",
|
|
44
|
-
"husky": "9.1.7",
|
|
45
|
-
"jest": "30.2.0",
|
|
46
|
-
"lint-staged": "^16.2.7",
|
|
47
|
-
"prettier": "3.7.4"
|
|
20
|
+
"mocha": "11.7.5"
|
|
48
21
|
}
|
|
49
22
|
}
|
package/src/index.js
DELETED