@carecard/validate 3.1.13 → 3.1.15

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/.husky/pre-commit CHANGED
@@ -1,3 +1,5 @@
1
+ npm run lint:fix
2
+ npm run format
3
+
1
4
  # Run tests
2
- npm run test
3
- npm run test:types
5
+ npm run test:All
package/.prettierrc.js ADDED
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ arrowParens: 'avoid',
3
+ bracketSameLine: true,
4
+ bracketSpacing: true,
5
+ singleQuote: true,
6
+ trailingComma: 'all',
7
+ printWidth: 140,
8
+ useTabs: false,
9
+ endOfLine: 'auto',
10
+ importOrderSeparation: true,
11
+ importOrderSortSpecifiers: true,
12
+ };
@@ -0,0 +1,14 @@
1
+ import { defineConfig, globalIgnores } from 'eslint/config';
2
+
3
+ const eslintConfig = defineConfig([
4
+ globalIgnores([
5
+ // Default ignores of eslint-config-next:
6
+ '.next/**',
7
+ 'out/**',
8
+ 'build/**',
9
+ 'next-env.d.ts',
10
+ 'node_modules/**',
11
+ ]),
12
+ ]);
13
+
14
+ export default eslintConfig;
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
- const validate = require( './lib/validate' );
2
- const validateProperties = require( './lib/validateProperties' );
1
+ const validate = require('./lib/validate');
2
+ const validateProperties = require('./lib/validateProperties');
3
3
 
4
4
  module.exports = {
5
- validate,
6
- validateProperties,
7
- ...validate,
8
- ...validateProperties
9
- }
5
+ validate,
6
+ validateProperties,
7
+ ...validate,
8
+ ...validateProperties,
9
+ };
package/lib/validate.js CHANGED
@@ -1,23 +1,16 @@
1
- const isImageUrl = (imageUrl) => {
2
- if (
3
- imageUrl === undefined ||
4
- typeof imageUrl !== 'string' ||
5
- imageUrl.length === 0 ||
6
- imageUrl.length > 2048
7
- )
8
- return false;
1
+ const isImageUrl = imageUrl => {
2
+ if (imageUrl === undefined || typeof imageUrl !== 'string' || imageUrl.length === 0 || imageUrl.length > 2048) return false;
9
3
 
10
4
  const imageUrlRegex = /^[a-zA-Z0-9-_./]+$/;
11
5
  return imageUrlRegex.test(imageUrl);
12
6
  };
13
7
 
14
- const isInteger = (number) => {
8
+ const isInteger = number => {
15
9
  return Number.isInteger(number);
16
10
  };
17
11
 
18
- const isValidJsonString = (str) => {
19
- if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 10000)
20
- return false;
12
+ const isValidJsonString = str => {
13
+ if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 10000) return false;
21
14
 
22
15
  try {
23
16
  const json = JSON.parse(str);
@@ -27,37 +20,35 @@ const isValidJsonString = (str) => {
27
20
  }
28
21
  };
29
22
 
30
- const isValidIntegerString = (str) => {
31
- if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 20)
32
- return false;
23
+ const isValidIntegerString = str => {
24
+ if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 20) return false;
33
25
  return /^\d+$/.test(str);
34
26
  };
35
27
 
36
- const isValidUuidString = (str) => {
28
+ const isValidUuidString = str => {
37
29
  if (str === undefined || typeof str !== 'string' || str.length === 0) return false;
38
30
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
39
31
  return uuidRegex.test(str);
40
32
  };
41
33
 
42
- const isCharactersString = (str) => {
43
- if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 1000)
44
- return false;
34
+ const isCharactersString = str => {
35
+ if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 1000) return false;
45
36
  return /^[\da-zA-Z _-]+$/.test(str);
46
37
  };
47
38
 
48
- const isNameString = (str) => {
39
+ const isNameString = str => {
49
40
  if (typeof str !== 'string' || str.length === 0 || str.length > 1000) {
50
41
  return false;
51
42
  }
52
43
  return /^[A-Za-z][0-9a-zA-Z-_.,'() ]+$/.test(str.trim());
53
44
  };
54
45
 
55
- const isSafeSearchString = (str) => {
46
+ const isSafeSearchString = str => {
56
47
  if (typeof str !== 'string' || str.length === 0) return false;
57
48
  return /^[A-Za-z][0-9a-zA-Z\-_.,'()@ ]{1,100}$/.test(str.trim());
58
49
  };
59
50
 
60
- const isEmailString = (email) => {
51
+ const isEmailString = email => {
61
52
  if (typeof email !== 'string' || email.length === 0 || email.length > 320) {
62
53
  return false;
63
54
  }
@@ -67,26 +58,25 @@ const isEmailString = (email) => {
67
58
  return regExpEmail.test(email);
68
59
  };
69
60
 
70
- const isJwtString = (jwt) => {
71
- if (typeof jwt !== 'string' || jwt.length === 0 || jwt.length > 8192 || jwt.trim() === '')
72
- return false;
61
+ const isJwtString = jwt => {
62
+ if (typeof jwt !== 'string' || jwt.length === 0 || jwt.length > 8192 || jwt.trim() === '') return false;
73
63
  const jwtRegex = /^eyJ[a-zA-Z0-9-_.]+$/;
74
64
  return jwtRegex.test(jwt);
75
65
  };
76
66
 
77
- const isPasswordString = (password) => {
67
+ const isPasswordString = password => {
78
68
  if (typeof password !== 'string' || password.length === 0 || password.length > 128) return false;
79
69
  const regExPassword = /^(?=.*[a-zA-Z0-9])(?=.*[!@#$%^&*_-])[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
80
70
  return regExPassword.test(String(password));
81
71
  };
82
72
 
83
- const isSimplePasswordString = (password) => {
73
+ const isSimplePasswordString = password => {
84
74
  if (typeof password !== 'string' || password.length === 0 || password.length > 128) return false;
85
75
  const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
86
76
  return regExPassword.test(String(password));
87
77
  };
88
78
 
89
- const isPasswordStringFailureMessage = (password) => {
79
+ const isPasswordStringFailureMessage = password => {
90
80
  if (!isPasswordString(password)) {
91
81
  return 'Total 6 to 32 characters, numbers and one of !@#$%^&*_-';
92
82
  } else {
@@ -94,7 +84,7 @@ const isPasswordStringFailureMessage = (password) => {
94
84
  }
95
85
  };
96
86
 
97
- const isSimplePasswordStringFailureMessage = (password) => {
87
+ const isSimplePasswordStringFailureMessage = password => {
98
88
  if (!isSimplePasswordString(password)) {
99
89
  return 'Total 6 to 32 characters, numbers or !@#$%^&*_-';
100
90
  } else {
@@ -102,7 +92,7 @@ const isSimplePasswordStringFailureMessage = (password) => {
102
92
  }
103
93
  };
104
94
 
105
- const isUsernameString = (str) => {
95
+ const isUsernameString = str => {
106
96
  if (typeof str !== 'string' || str.length === 0 || str.length > 200) return false;
107
97
  return /^[0-9a-zA-Z]+$/.test(str);
108
98
  };
@@ -112,29 +102,23 @@ function isPhoneNumber(str) {
112
102
  return /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/.test(str);
113
103
  }
114
104
 
115
- const isUrlSafeString = (inputString) => {
116
- if (
117
- typeof inputString !== 'string' ||
118
- inputString.length === 0 ||
119
- inputString.length > 2048 ||
120
- inputString.trim() === ''
121
- )
122
- return false;
105
+ const isUrlSafeString = inputString => {
106
+ if (typeof inputString !== 'string' || inputString.length === 0 || inputString.length > 2048 || inputString.trim() === '') return false;
123
107
  const urlSafeRegex = /^[a-zA-Z0-9-_.]+$/;
124
108
  return urlSafeRegex.test(inputString);
125
109
  };
126
110
 
127
- const isString6To24CharacterLong = (password) => {
111
+ const isString6To24CharacterLong = password => {
128
112
  if (typeof password !== 'string' || password.length === 0) return false;
129
113
  return 6 <= password.length && password.length <= 24;
130
114
  };
131
115
 
132
- const isString6To16CharacterLong = (password) => {
116
+ const isString6To16CharacterLong = password => {
133
117
  if (typeof password !== 'string' || password.length === 0) return false;
134
118
  return 6 <= password.length && password.length <= 16;
135
119
  };
136
120
 
137
- const isProvinceString = (inputString) => {
121
+ const isProvinceString = inputString => {
138
122
  const provinces = ['on', 'qc'];
139
123
 
140
124
  if (isNameString(inputString)) {
@@ -144,11 +128,11 @@ const isProvinceString = (inputString) => {
144
128
  return false;
145
129
  };
146
130
 
147
- const isBoolValue = (inputValue) => {
131
+ const isBoolValue = inputValue => {
148
132
  return typeof inputValue === 'boolean' || inputValue === 'true' || inputValue === 'false';
149
133
  };
150
134
 
151
- const isPostalCodeString = (inputString) => {
135
+ const isPostalCodeString = inputString => {
152
136
  const postalCodeRegex = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$/i;
153
137
 
154
138
  if (isNameString(inputString)) {
@@ -158,7 +142,7 @@ const isPostalCodeString = (inputString) => {
158
142
  return false;
159
143
  };
160
144
 
161
- const isSafeString = (str) => {
145
+ const isSafeString = str => {
162
146
  if (typeof str !== 'string' || str.length === 0 || str.length > 10000) return false;
163
147
  return /^[\da-zA-Z-_.,#*'()[\]: ]+$/.test(str);
164
148
  };
@@ -171,7 +155,7 @@ const isInStringArray = (StringArray, inputString) => {
171
155
  return false;
172
156
  };
173
157
 
174
- const isCountryCodeString = (str) => {
158
+ const isCountryCodeString = str => {
175
159
  if (typeof str !== 'string' || str.length === 0 || str.length > 4) return false;
176
160
 
177
161
  const countryCodeRegex = /^\+[1-9][0-9]{0,2}$/;
@@ -179,28 +163,28 @@ const isCountryCodeString = (str) => {
179
163
  return countryCodeRegex.test(str);
180
164
  };
181
165
 
182
- const isValidDomainName = (domain) => {
166
+ const isValidDomainName = domain => {
183
167
  if (typeof domain !== 'string' || domain.length === 0 || domain.length > 253) return false;
184
168
 
185
169
  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
170
  return domainRegex.test(domain);
187
171
  };
188
172
 
189
- const isValidTimestampzString = (str) => {
173
+ const isValidTimestampzString = str => {
190
174
  if (typeof str !== 'string' || str.length === 0 || str.length > 64) return false;
191
175
  // ISO 8601 for UTC or with Offset: 2023-10-27T10:00:00Z or 2023-10-27T10:00:00+02:00
192
176
  const timestampzRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
193
177
  return timestampzRegex.test(str) && !isNaN(Date.parse(str));
194
178
  };
195
179
 
196
- const isValidTimestampString = (str) => {
180
+ const isValidTimestampString = str => {
197
181
  if (typeof str !== 'string' || str.length === 0 || str.length > 64) return false;
198
182
  // ISO 8601 without time zone: 2023-10-27T10:00:00 or 2023-10-27T10:00:00.123
199
183
  const timestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/;
200
184
  return timestampRegex.test(str) && !isNaN(Date.parse(str));
201
185
  };
202
186
 
203
- const isValidUrl = (url) => {
187
+ const isValidUrl = url => {
204
188
  if (typeof url !== 'string' || url.length === 0 || url.length > 2048) return false;
205
189
  try {
206
190
  const parsedUrl = new URL(url);
@@ -209,39 +193,39 @@ const isValidUrl = (url) => {
209
193
  return false;
210
194
  }
211
195
  };
212
- const isValidArrayOfStrings = (arr) => {
196
+ const isValidArrayOfStrings = arr => {
213
197
  if (!Array.isArray(arr)) return false;
214
198
  return arr.every(isSafeString);
215
199
  };
216
200
  module.exports = {
217
- isImageUrl,
218
- isInteger,
219
- isValidJsonString,
220
- isValidIntegerString,
221
- isValidUuidString,
222
- isCharactersString,
223
- isNameString,
224
- isSafeSearchString,
225
- isEmailString,
226
- isJwtString,
227
- isPasswordString,
228
- isSimplePasswordString,
229
- isPasswordStringFailureMessage,
230
- isSimplePasswordStringFailureMessage,
231
- isUsernameString,
232
- isPhoneNumber,
233
- isUrlSafeString,
234
- isString6To24CharacterLong,
235
- isString6To16CharacterLong,
236
- isProvinceString,
237
- isBoolValue,
238
- isPostalCodeString,
239
- isSafeString,
240
- isInStringArray,
241
- isCountryCodeString,
242
- isValidDomainName,
243
- isValidTimestampzString,
244
- isValidTimestampString,
245
- isValidUrl,
246
- isValidArrayOfStrings
201
+ isImageUrl,
202
+ isInteger,
203
+ isValidJsonString,
204
+ isValidIntegerString,
205
+ isValidUuidString,
206
+ isCharactersString,
207
+ isNameString,
208
+ isSafeSearchString,
209
+ isEmailString,
210
+ isJwtString,
211
+ isPasswordString,
212
+ isSimplePasswordString,
213
+ isPasswordStringFailureMessage,
214
+ isSimplePasswordStringFailureMessage,
215
+ isUsernameString,
216
+ isPhoneNumber,
217
+ isUrlSafeString,
218
+ isString6To24CharacterLong,
219
+ isString6To16CharacterLong,
220
+ isProvinceString,
221
+ isBoolValue,
222
+ isPostalCodeString,
223
+ isSafeString,
224
+ isInStringArray,
225
+ isCountryCodeString,
226
+ isValidDomainName,
227
+ isValidTimestampzString,
228
+ isValidTimestampString,
229
+ isValidUrl,
230
+ isValidArrayOfStrings,
247
231
  };
@@ -1,207 +1,230 @@
1
1
  // Validate the property values format.
2
2
  const {
3
- isEmailString,
4
- isPhoneNumber,
5
- isUrlSafeString,
6
- isValidUuidString,
7
- isSimplePasswordString,
8
- isPasswordString,
9
- isString6To16CharacterLong,
10
- isNameString,
11
- isSafeSearchString,
12
- isCharactersString,
13
- isValidIntegerString,
14
- isValidJsonString,
15
- isImageUrl,
16
- isValidDomainName,
17
- isValidTimestampzString,
18
- isValidTimestampString,
19
- isBoolValue,
20
- isValidUrl,
21
- isValidArrayOfStrings,
3
+ isEmailString,
4
+ isPhoneNumber,
5
+ isUrlSafeString,
6
+ isValidUuidString,
7
+ isSimplePasswordString,
8
+ isPasswordString,
9
+ isString6To16CharacterLong,
10
+ isNameString,
11
+ isSafeSearchString,
12
+ isCharactersString,
13
+ isValidIntegerString,
14
+ isValidJsonString,
15
+ isImageUrl,
16
+ isValidDomainName,
17
+ isValidTimestampzString,
18
+ isValidTimestampString,
19
+ isBoolValue,
20
+ isValidUrl,
21
+ isValidArrayOfStrings,
22
22
  } = require('./validate');
23
23
 
24
24
  function validateProperties(obj = {}) {
25
- const returnObj = {};
25
+ const returnObj = {};
26
26
 
27
- for (const [key, value] of Object.entries(obj || {})) {
28
- switch (key) {
29
- case 'first_name':
30
- case 'firstName':
31
- case 'username':
32
- case 'new_status':
33
- case 'newStatus':
34
- case 'description':
35
- case 'comment':
36
- case 'status':
37
- case 'name':
38
- case 'title':
39
- case 'brand':
40
- case 'short_description':
41
- case 'shortDescription':
42
- case 'college_name':
43
- case 'collegeName':
44
- case 'campus_name':
45
- case 'campusName':
46
- case 'role':
47
- case 'role_id':
48
- case 'roleId':
49
- case 'campus':
50
- case 'institution_name':
51
- case 'institutionName':
52
- case 'program_name':
53
- case 'programName':
54
- case 'role_name':
55
- case 'roleName':
56
- case 'document_type':
57
- case 'documentType':
58
- case 'reason':
59
- case 'type':
60
- if (isNameString(value) || (typeof value === 'object' && value !== null)) {
61
- returnObj[key] = value;
62
- }
63
- break;
64
- case 'search_string':
65
- case 'searchString':
66
- if (isSafeSearchString(value)) {
67
- returnObj[key] = value;
68
- }
69
- break;
70
- case 'password':
71
- case 'new_password':
72
- case 'newPassword':
73
- if (isString6To16CharacterLong(value) && isSimplePasswordString(value)) {
74
- returnObj[key] = value;
75
- }
76
- break;
77
- case 'strong_password':
78
- case 'strongPassword':
79
- if (isString6To16CharacterLong(value) && isPasswordString(value)) {
80
- returnObj[key] = value;
81
- }
82
- break;
83
- case 'email':
84
- if (isEmailString(value)) {
85
- returnObj[key] = value;
86
- }
87
- break;
88
- case 'phone_number':
89
- case 'phoneNumber':
90
- if (isPhoneNumber(value)) {
91
- returnObj[key] = value;
92
- }
93
- break;
94
- case 'token':
95
- case 'email_confirm_token':
96
- case 'emailConfirmToken':
97
- case 'verification_token':
98
- case 'verificationToken':
99
- if (isUrlSafeString(value)) {
100
- returnObj[key] = value;
101
- }
102
- break;
103
- case 'uuid':
104
- case 'item_id':
105
- case 'user_id':
106
- case 'image_id':
107
- case 'itemId':
108
- case 'userId':
109
- case 'imageId':
110
- case 'order_id':
111
- case 'orderId':
112
- case 'category_id':
113
- case 'categoryId':
114
- case 'parent_id':
115
- case 'parentId':
116
- case 'college_id':
117
- case 'collegeId':
118
- case 'campus_id':
119
- case 'campusId':
120
- case 'program_id':
121
- case 'programId':
122
- case 'id':
123
- case 'institution_id':
124
- case 'institutionId':
125
- case 'role_assignment_id':
126
- case 'roleAssignmentId':
127
- case 'user_role_id':
128
- case 'userRoleId':
129
- if (isValidUuidString(value)) {
130
- returnObj[key] = value;
131
- }
132
- break;
133
- case 'period':
134
- if (isCharactersString(value)) {
135
- returnObj[key] = value;
136
- }
137
- break;
138
- case 'offset_number':
139
- case 'offsetNumber':
140
- case 'number_of_orders':
141
- case 'numberOfOrders':
142
- case 'price':
143
- if (isValidIntegerString(value)) {
144
- returnObj[key] = value;
145
- }
146
- break;
147
- case 'about':
148
- if (isValidJsonString(value)) {
149
- returnObj[key] = value.trim();
150
- }
151
- break;
152
- case 'weight':
153
- case 'dimensions':
154
- case 'permission':
155
- case 'scope_data':
156
- case 'scopeData':
157
- case 'meta_data':
158
- case 'metaData':
159
- if (isValidJsonString(JSON.stringify(value))) {
160
- returnObj[key] = value;
161
- }
162
- break;
163
- case 'aliases':
164
- if (isValidArrayOfStrings(value)) {
165
- returnObj[key] = value;
166
- }
167
- break;
168
- case 'image_url':
169
- case 'imageUrl':
170
- case 'website':
171
- case 'file_url':
172
- case 'fileUrl':
173
- if (isImageUrl(value) || isValidUrl(value)) {
174
- returnObj[key] = value;
175
- }
176
- break;
177
- case 'domain_name':
178
- case 'domainName':
179
- case 'domain':
180
- case 'email_domain':
181
- case 'emailDomain':
182
- case 'email_domain_name':
183
- case 'emailDomainName':
184
- if (isValidDomainName(value)) {
185
- returnObj[key] = value;
186
- }
187
- break;
188
- case 'expires_at':
189
- case 'expiresAt':
190
- if (isValidTimestampzString(value) || isValidTimestampString(value)) {
191
- returnObj[key] = value;
192
- }
193
- break;
194
- case 'active':
195
- if (isBoolValue(value)) {
196
- returnObj[key] = value;
197
- }
198
- break;
27
+ for (const [key, value] of Object.entries(obj || {})) {
28
+ switch (key) {
29
+ case 'first_name':
30
+ case 'firstName':
31
+ case 'last_name':
32
+ case 'lastName':
33
+ case 'username':
34
+ case 'new_status':
35
+ case 'newStatus':
36
+ case 'description':
37
+ case 'comment':
38
+ case 'status':
39
+ case 'name':
40
+ case 'title':
41
+ case 'brand':
42
+ case 'short_description':
43
+ case 'shortDescription':
44
+ case 'college_name':
45
+ case 'collegeName':
46
+ case 'campus_name':
47
+ case 'campusName':
48
+ case 'role':
49
+ case 'role_id':
50
+ case 'roleId':
51
+ case 'campus':
52
+ case 'institution_name':
53
+ case 'institutionName':
54
+ case 'program_name':
55
+ case 'programName':
56
+ case 'role_name':
57
+ case 'roleName':
58
+ case 'document_type':
59
+ case 'documentType':
60
+ case 'reason':
61
+ case 'street':
62
+ case 'city':
63
+ case 'state':
64
+ case 'country':
65
+ case 'type':
66
+ if (isNameString(value) || (typeof value === 'object' && value !== null)) {
67
+ returnObj[key] = value;
199
68
  }
69
+ break;
70
+ case 'postal_code':
71
+ case 'postalCode':
72
+ if (isCharactersString(value)) {
73
+ returnObj[key] = value;
74
+ }
75
+ break;
76
+
77
+ case 'is_primary':
78
+ case 'isPrimary':
79
+ if (isBoolValue(value)) {
80
+ returnObj[key] = value;
81
+ }
82
+ break;
83
+ case 'search_string':
84
+ case 'searchString':
85
+ if (isSafeSearchString(value)) {
86
+ returnObj[key] = value;
87
+ }
88
+ break;
89
+ case 'password':
90
+ case 'new_password':
91
+ case 'newPassword':
92
+ if (isString6To16CharacterLong(value) && isSimplePasswordString(value)) {
93
+ returnObj[key] = value;
94
+ }
95
+ break;
96
+ case 'strong_password':
97
+ case 'strongPassword':
98
+ if (isString6To16CharacterLong(value) && isPasswordString(value)) {
99
+ returnObj[key] = value;
100
+ }
101
+ break;
102
+ case 'email':
103
+ if (isEmailString(value)) {
104
+ returnObj[key] = value;
105
+ }
106
+ break;
107
+ case 'phone_number':
108
+ case 'phoneNumber':
109
+ if (isPhoneNumber(value)) {
110
+ returnObj[key] = value;
111
+ }
112
+ break;
113
+ case 'token':
114
+ case 'email_confirm_token':
115
+ case 'emailConfirmToken':
116
+ case 'verification_token':
117
+ case 'verificationToken':
118
+ if (isUrlSafeString(value)) {
119
+ returnObj[key] = value;
120
+ }
121
+ break;
122
+ case 'uuid':
123
+ case 'item_id':
124
+ case 'user_id':
125
+ case 'address_id':
126
+ case 'addressId':
127
+ case 'image_id':
128
+ case 'itemId':
129
+ case 'userId':
130
+ case 'imageId':
131
+ case 'order_id':
132
+ case 'orderId':
133
+ case 'category_id':
134
+ case 'categoryId':
135
+ case 'parent_id':
136
+ case 'parentId':
137
+ case 'college_id':
138
+ case 'collegeId':
139
+ case 'campus_id':
140
+ case 'campusId':
141
+ case 'program_id':
142
+ case 'programId':
143
+ case 'id':
144
+ case 'institution_id':
145
+ case 'institutionId':
146
+ case 'role_assignment_id':
147
+ case 'roleAssignmentId':
148
+ case 'user_role_id':
149
+ case 'userRoleId':
150
+ if (isValidUuidString(value)) {
151
+ returnObj[key] = value;
152
+ }
153
+ break;
154
+ case 'period':
155
+ if (isCharactersString(value)) {
156
+ returnObj[key] = value;
157
+ }
158
+ break;
159
+ case 'offset_number':
160
+ case 'offsetNumber':
161
+ case 'number_of_orders':
162
+ case 'numberOfOrders':
163
+ case 'price':
164
+ case 'from':
165
+ case 'number':
166
+ if (isValidIntegerString(value)) {
167
+ returnObj[key] = value;
168
+ }
169
+ break;
170
+ case 'about':
171
+ if (isValidJsonString(value)) {
172
+ returnObj[key] = value.trim();
173
+ }
174
+ break;
175
+ case 'weight':
176
+ case 'dimensions':
177
+ case 'permission':
178
+ case 'scope_data':
179
+ case 'scopeData':
180
+ case 'meta_data':
181
+ case 'metaData':
182
+ if (isValidJsonString(JSON.stringify(value))) {
183
+ returnObj[key] = value;
184
+ }
185
+ break;
186
+ case 'aliases':
187
+ if (isValidArrayOfStrings(value)) {
188
+ returnObj[key] = value;
189
+ }
190
+ break;
191
+ case 'image_url':
192
+ case 'imageUrl':
193
+ case 'website':
194
+ case 'file_url':
195
+ case 'fileUrl':
196
+ if (isImageUrl(value) || isValidUrl(value)) {
197
+ returnObj[key] = value;
198
+ }
199
+ break;
200
+ case 'domain_name':
201
+ case 'domainName':
202
+ case 'domain':
203
+ case 'email_domain':
204
+ case 'emailDomain':
205
+ case 'email_domain_name':
206
+ case 'emailDomainName':
207
+ if (isValidDomainName(value)) {
208
+ returnObj[key] = value;
209
+ }
210
+ break;
211
+ case 'expires_at':
212
+ case 'expiresAt':
213
+ if (isValidTimestampzString(value) || isValidTimestampString(value)) {
214
+ returnObj[key] = value;
215
+ }
216
+ break;
217
+ case 'active':
218
+ if (isBoolValue(value)) {
219
+ returnObj[key] = value;
220
+ }
221
+ break;
200
222
  }
223
+ }
201
224
 
202
- return returnObj;
225
+ return returnObj;
203
226
  }
204
227
 
205
228
  module.exports = {
206
- validateProperties,
229
+ validateProperties,
207
230
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/validate",
3
- "version": "3.1.13",
3
+ "version": "3.1.15",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/CareCard-ca/pkg-validate.git"
@@ -11,8 +11,13 @@
11
11
  "scripts": {
12
12
  "test": "mocha --recursive",
13
13
  "test:types": "tsc --noEmit && mocha -r ts-node/register test/types.test.ts",
14
+ "test:coverage": "tsc --noEmit && export NODE_ENV=test && nyc mocha --recursive -r ts-node/register 'test/**/*.{js,ts}'",
14
15
  "test:All": "npm run test && npm run test:types",
15
- "prepare": "husky"
16
+ "format": "prettier --write .",
17
+ "format:check": "prettier --check .",
18
+ "prepare": "husky",
19
+ "lint:fix": "eslint --fix",
20
+ "lint": "eslint"
16
21
  },
17
22
  "keywords": [
18
23
  "validate",
@@ -22,9 +27,13 @@
22
27
  "license": "ISC",
23
28
  "devDependencies": {
24
29
  "@types/mocha": "10.0.10",
25
- "@types/node": "25.5.0",
26
- "husky": "^9.1.7",
30
+ "@types/node": "25.6.2",
31
+ "eslint": "9.39.4",
32
+ "husky": "9.1.7",
33
+ "lint-staged": "17.0.3",
27
34
  "mocha": "11.7.5",
35
+ "nyc": "18.0.0",
36
+ "prettier": "3.8.3",
28
37
  "ts-node": "10.9.2",
29
38
  "typescript": "5.9.3"
30
39
  }
package/readme.md CHANGED
@@ -1,24 +1,29 @@
1
1
  #Validate
2
+
2
3
  ### Functions
3
4
 
4
5
  All functions return boolean value, false on failure
5
6
 
6
7
  - Validates that a string is string of characters
8
+
7
9
  ```js
8
- isStringOfCharacters(str)
10
+ isStringOfCharacters(str);
9
11
  ```
10
12
 
11
13
  - Validates that a string is fit for username
14
+
12
15
  ```js
13
- isStringOfUsername(str)
16
+ isStringOfUsername(str);
14
17
  ```
15
18
 
16
19
  - Validates that string is an email
20
+
17
21
  ```js
18
- isEmail(email)
22
+ isEmail(email);
19
23
  ```
20
24
 
21
25
  - Validates that string is fit for password
26
+
22
27
  ```js
23
- isStringOfPassword(password)
24
- ```
28
+ isStringOfPassword(password);
29
+ ```