@carecard/validate 2.0.4 → 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 CHANGED
@@ -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,104 +1,112 @@
1
1
  // Validate the property values format.
2
2
  const {
3
- isEmailString,
4
- isPhoneNumber,
5
- isUrlSafeString,
6
- isValidUuidString,
7
- isSimplePasswordString,
8
- isPasswordString,
9
- isNameString,
10
- isSafeSearchString,
11
- isCharactersString,
12
- isValidIntegerString,
13
- isValidJsonString, isImageUrl
14
- } = require( "./validate" );
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');
15
17
 
16
- function validateProperties( obj ) {
17
- let returnObj = {};
18
+ function validateProperties(obj) {
19
+ let returnObj = {};
18
20
 
19
- for ( let [ key, value ] of Object.entries( obj || {} ) ) {
21
+ for (let [key, value] of Object.entries(obj || {})) {
20
22
 
21
- switch ( key ) {
22
- case "first_name" :
23
- case "username" :
24
- case "newStatus":
25
- case "description":
26
- case "comment":
27
- case "status":
28
- case "name":
29
- case "title" :
30
- case "brand":
31
- case "short_description" :
32
- isNameString( value ) ?
33
- returnObj[ key ] = value : null;
34
- break;
35
- case "search_string":
36
- case "searchString":
37
- isSafeSearchString( value ) ?
38
- returnObj[ key ] = value : null;
39
- break;
40
- case "password" :
41
- case "new_password" :
42
- isSimplePasswordString( value ) ?
43
- returnObj[ key ] = value : null;
44
- break;
45
- case "strong_password" :
46
- isPasswordString( value ) ?
47
- returnObj[ key ] = value : null;
48
- break;
49
- case "email" :
50
- isEmailString( value ) ?
51
- returnObj[ key ] = value : null;
52
- break;
53
- case "phone_number":
54
- isPhoneNumber( value ) ?
55
- returnObj[ key ] = value : null;
56
- break;
57
- case "token":
58
- case "email_confirm_token":
59
- case "verification_token":
60
- isUrlSafeString( value ) ?
61
- returnObj[ key ] = value : null;
62
- break;
63
- case "uuid":
64
- case "item_id":
65
- case "user_id":
66
- case "userId":
67
- case "image_id":
68
- case "itemId":
69
- case "orderId":
70
- case "category_id":
71
- case "parent_id":
72
- isValidUuidString( value ) ?
73
- returnObj[ key ] = value : null;
74
- break;
75
- case "period":
76
- isCharactersString( value ) ?
77
- returnObj[ key ] = value : null;
78
- break;
79
- case "offset_number":
80
- case "number_of_orders":
81
- case "price":
82
- isValidIntegerString( value ) ?
83
- returnObj[ key ] = value : null;
84
- break;
85
- case "about":
86
- isValidJsonString( value ) ? returnObj[ key ] = value.trim() : null;
87
- break;
88
- case "weight":
89
- case "dimensions":
90
- case "permission":
91
- isValidJsonString( JSON.stringify( value ) ) ? returnObj[ key ] = value : null;
92
- break;
93
- case "image_url":
94
- isImageUrl( value ) ? returnObj[ key ] = value : null;
95
- break;
96
- }
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;
97
104
  }
105
+ }
98
106
 
99
- return returnObj;
107
+ return returnObj;
100
108
  }
101
109
 
102
110
  module.exports = {
103
- validateProperties
111
+ validateProperties,
104
112
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/validate",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/CareCard-ca/pkg-validate.git"