@carecard/validate 2.2.7 → 2.2.10

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.
@@ -1,148 +1,159 @@
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,
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
17
  } = require('./validate');
18
18
 
19
19
  function validateProperties(obj = {}) {
20
- const returnObj = {};
20
+ const returnObj = {};
21
21
 
22
- for (const [key, value] of Object.entries(obj || {})) {
23
- switch (key) {
24
- case 'first_name':
25
- case 'firstName':
26
- case 'username':
27
- case 'new_status':
28
- case 'newStatus':
29
- case 'description':
30
- case 'comment':
31
- case 'status':
32
- case 'name':
33
- case 'title':
34
- case 'brand':
35
- case 'short_description':
36
- case 'shortDescription':
37
- if (isNameString(value)) {
38
- returnObj[key] = value;
22
+ for (const [key, value] of Object.entries(obj || {})) {
23
+ switch (key) {
24
+ case 'first_name':
25
+ case 'firstName':
26
+ case 'username':
27
+ case 'new_status':
28
+ case 'newStatus':
29
+ case 'description':
30
+ case 'comment':
31
+ case 'status':
32
+ case 'name':
33
+ case 'title':
34
+ case 'brand':
35
+ case 'short_description':
36
+ case 'shortDescription':
37
+ case 'college_name':
38
+ case 'collegeName':
39
+ case 'campus_name':
40
+ case 'campusName':
41
+ case 'role':
42
+ if (isNameString(value)) {
43
+ returnObj[key] = value;
44
+ }
45
+ break;
46
+ case 'search_string':
47
+ case 'searchString':
48
+ if (isSafeSearchString(value)) {
49
+ returnObj[key] = value;
50
+ }
51
+ break;
52
+ case 'password':
53
+ case 'new_password':
54
+ case 'newPassword':
55
+ if (isString6To16CharacterLong(value) && isSimplePasswordString(value)) {
56
+ returnObj[key] = value;
57
+ }
58
+ break;
59
+ case 'strong_password':
60
+ case 'strongPassword':
61
+ if (isString6To16CharacterLong(value) && isPasswordString(value)) {
62
+ returnObj[key] = value;
63
+ }
64
+ break;
65
+ case 'email':
66
+ if (isEmailString(value)) {
67
+ returnObj[key] = value;
68
+ }
69
+ break;
70
+ case 'phone_number':
71
+ case 'phoneNumber':
72
+ if (isPhoneNumber(value)) {
73
+ returnObj[key] = value;
74
+ }
75
+ break;
76
+ case 'token':
77
+ case 'email_confirm_token':
78
+ case 'emailConfirmToken':
79
+ case 'verification_token':
80
+ case 'verificationToken':
81
+ if (isUrlSafeString(value)) {
82
+ returnObj[key] = value;
83
+ }
84
+ break;
85
+ case 'uuid':
86
+ case 'item_id':
87
+ case 'user_id':
88
+ case 'image_id':
89
+ case 'itemId':
90
+ case 'userId':
91
+ case 'imageId':
92
+ case 'order_id':
93
+ case 'orderId':
94
+ case 'category_id':
95
+ case 'categoryId':
96
+ case 'parent_id':
97
+ case 'parentId':
98
+ case 'college_id':
99
+ case 'collegeId':
100
+ case 'campus_id':
101
+ case 'campusId':
102
+ case 'program_id':
103
+ case 'programId':
104
+ if (isValidUuidString(value)) {
105
+ returnObj[key] = value;
106
+ }
107
+ break;
108
+ case 'period':
109
+ if (isCharactersString(value)) {
110
+ returnObj[key] = value;
111
+ }
112
+ break;
113
+ case 'offset_number':
114
+ case 'offsetNumber':
115
+ case 'number_of_orders':
116
+ case 'numberOfOrders':
117
+ case 'price':
118
+ if (isValidIntegerString(value)) {
119
+ returnObj[key] = value;
120
+ }
121
+ break;
122
+ case 'about':
123
+ if (isValidJsonString(value)) {
124
+ returnObj[key] = value.trim();
125
+ }
126
+ break;
127
+ case 'weight':
128
+ case 'dimensions':
129
+ case 'permission':
130
+ if (isValidJsonString(JSON.stringify(value))) {
131
+ returnObj[key] = value;
132
+ }
133
+ break;
134
+ case 'image_url':
135
+ case 'imageUrl':
136
+ if (isImageUrl(value)) {
137
+ returnObj[key] = value;
138
+ }
139
+ break;
140
+ case 'domain_name':
141
+ case 'domainName':
142
+ case 'domain':
143
+ case 'email_domain':
144
+ case 'emailDomain':
145
+ case 'email_domain_name':
146
+ case 'emailDomainName':
147
+ if (isValidDomainName(value)) {
148
+ returnObj[key] = value;
149
+ }
150
+ break;
39
151
  }
40
- break;
41
- case 'search_string':
42
- case 'searchString':
43
- if (isSafeSearchString(value)) {
44
- returnObj[key] = value;
45
- }
46
- break;
47
- case 'password':
48
- case 'new_password':
49
- case 'newPassword':
50
- if (isString6To16CharacterLong(value) && isSimplePasswordString(value)) {
51
- returnObj[key] = value;
52
- }
53
- break;
54
- case 'strong_password':
55
- case 'strongPassword':
56
- if (isString6To16CharacterLong(value) && isPasswordString(value)) {
57
- returnObj[key] = value;
58
- }
59
- break;
60
- case 'email':
61
- if (isEmailString(value)) {
62
- returnObj[key] = value;
63
- }
64
- break;
65
- case 'phone_number':
66
- case 'phoneNumber':
67
- if (isPhoneNumber(value)) {
68
- returnObj[key] = value;
69
- }
70
- break;
71
- case 'token':
72
- case 'email_confirm_token':
73
- case 'emailConfirmToken':
74
- case 'verification_token':
75
- case 'verificationToken':
76
- if (isUrlSafeString(value)) {
77
- returnObj[key] = value;
78
- }
79
- break;
80
- case 'uuid':
81
- case 'item_id':
82
- case 'user_id':
83
- case 'image_id':
84
- case 'itemId':
85
- case 'userId':
86
- case 'imageId':
87
- case 'order_id':
88
- case 'orderId':
89
- case 'category_id':
90
- case 'categoryId':
91
- case 'parent_id':
92
- case 'parentId':
93
- if (isValidUuidString(value)) {
94
- returnObj[key] = value;
95
- }
96
- break;
97
- case 'period':
98
- if (isCharactersString(value)) {
99
- returnObj[key] = value;
100
- }
101
- break;
102
- case 'offset_number':
103
- case 'offsetNumber':
104
- case 'number_of_orders':
105
- case 'numberOfOrders':
106
- case 'price':
107
- if (isValidIntegerString(value)) {
108
- returnObj[key] = value;
109
- }
110
- break;
111
- case 'about':
112
- if (isValidJsonString(value)) {
113
- returnObj[key] = value.trim();
114
- }
115
- break;
116
- case 'weight':
117
- case 'dimensions':
118
- case 'permission':
119
- if (isValidJsonString(JSON.stringify(value))) {
120
- returnObj[key] = value;
121
- }
122
- break;
123
- case 'image_url':
124
- case 'imageUrl':
125
- if (isImageUrl(value)) {
126
- returnObj[key] = value;
127
- }
128
- break;
129
- case 'domain_name':
130
- case 'domainName':
131
- case 'domain':
132
- case 'email_domain':
133
- case 'emailDomain':
134
- case 'email_domain_name':
135
- case 'emailDomainName':
136
- if (isValidDomainName(value)) {
137
- returnObj[key] = value;
138
- }
139
- break;
140
152
  }
141
- }
142
153
 
143
- return returnObj;
154
+ return returnObj;
144
155
  }
145
156
 
146
157
  module.exports = {
147
- validateProperties,
158
+ validateProperties,
148
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/validate",
3
- "version": "2.2.7",
3
+ "version": "2.2.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/CareCard-ca/pkg-validate.git"
@@ -17,6 +17,6 @@
17
17
  "author": "CareCard team",
18
18
  "license": "ISC",
19
19
  "devDependencies": {
20
- "mocha": "11.3.0"
20
+ "mocha": "11.7.5"
21
21
  }
22
22
  }