@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 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!@#$%^&*_-]{6,32}$/;
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
- isEmailString,
4
- isPhoneNumber,
5
- isUrlSafeString,
6
- isValidUuidString,
7
- isSimplePasswordString,
8
- isPasswordString,
9
- isString6To16CharacterLong,
10
- isNameString,
11
- isSafeSearchString,
12
- isCharactersString,
13
- isValidIntegerString,
14
- isValidJsonString, isImageUrl
15
- } = 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');
16
17
 
17
- function validateProperties( obj ) {
18
- let returnObj = {};
18
+ function validateProperties(obj) {
19
+ let returnObj = {};
19
20
 
20
- for ( let [ key, value ] of Object.entries( obj || {} ) ) {
21
+ for (let [key, value] of Object.entries(obj || {})) {
21
22
 
22
- switch ( key ) {
23
- case "first_name" :
24
- case "username" :
25
- case "newStatus":
26
- case "description":
27
- case "comment":
28
- case "status":
29
- case "name":
30
- case "title" :
31
- case "brand":
32
- case "short_description" :
33
- isNameString( value ) ?
34
- returnObj[ key ] = value : null;
35
- break;
36
- case "search_string":
37
- case "searchString":
38
- isSafeSearchString( value ) ?
39
- returnObj[ key ] = value : null;
40
- break;
41
- case "password" :
42
- case "new_password" :
43
- isString6To16CharacterLong( value ) && isSimplePasswordString( value ) ?
44
- returnObj[ key ] = value : null;
45
- break;
46
- case "strong_password" :
47
- isString6To16CharacterLong( value ) && isPasswordString( value ) ?
48
- returnObj[ key ] = value : null;
49
- break;
50
- case "email" :
51
- isEmailString( value ) ?
52
- returnObj[ key ] = value : null;
53
- break;
54
- case "phone_number":
55
- isPhoneNumber( value ) ?
56
- returnObj[ key ] = value : null;
57
- break;
58
- case "token":
59
- case "email_confirm_token":
60
- case "verification_token":
61
- isUrlSafeString( value ) ?
62
- returnObj[ key ] = value : null;
63
- break;
64
- case "uuid":
65
- case "item_id":
66
- case "user_id":
67
- case "userId":
68
- case "image_id":
69
- case "itemId":
70
- case "userId":
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
- }
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
- return returnObj;
107
+ return returnObj;
102
108
  }
103
109
 
104
110
  module.exports = {
105
- validateProperties
111
+ validateProperties,
106
112
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/validate",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/CareCard-ca/pkg-validate.git"