@carecard/validate 2.2.10 → 2.2.12
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 +17 -1
- package/lib/validateProperties.js +14 -0
- package/package.json +1 -1
package/lib/validate.js
CHANGED
|
@@ -185,6 +185,20 @@ const isValidDomainName = (domain) => {
|
|
|
185
185
|
return domainRegex.test(domain);
|
|
186
186
|
};
|
|
187
187
|
|
|
188
|
+
const isValidTimestampzString = (str) => {
|
|
189
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 64) return false;
|
|
190
|
+
// ISO 8601 for UTC or with Offset: 2023-10-27T10:00:00Z or 2023-10-27T10:00:00+02:00
|
|
191
|
+
const timestampzRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
|
|
192
|
+
return timestampzRegex.test(str) && !isNaN(Date.parse(str));
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const isValidTimestampString = (str) => {
|
|
196
|
+
if (typeof str !== 'string' || str.length === 0 || str.length > 64) return false;
|
|
197
|
+
// ISO 8601 without time zone: 2023-10-27T10:00:00 or 2023-10-27T10:00:00.123
|
|
198
|
+
const timestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/;
|
|
199
|
+
return timestampRegex.test(str) && !isNaN(Date.parse(str));
|
|
200
|
+
};
|
|
201
|
+
|
|
188
202
|
module.exports = {
|
|
189
203
|
isImageUrl,
|
|
190
204
|
isInteger,
|
|
@@ -211,5 +225,7 @@ module.exports = {
|
|
|
211
225
|
isSafeString,
|
|
212
226
|
isInStringArray,
|
|
213
227
|
isCountryCodeString,
|
|
214
|
-
isValidDomainName
|
|
228
|
+
isValidDomainName,
|
|
229
|
+
isValidTimestampzString,
|
|
230
|
+
isValidTimestampString
|
|
215
231
|
};
|
|
@@ -14,6 +14,9 @@ const {
|
|
|
14
14
|
isValidJsonString,
|
|
15
15
|
isImageUrl,
|
|
16
16
|
isValidDomainName,
|
|
17
|
+
isValidTimestampzString,
|
|
18
|
+
isValidTimestampString,
|
|
19
|
+
isBoolValue,
|
|
17
20
|
} = require('./validate');
|
|
18
21
|
|
|
19
22
|
function validateProperties(obj = {}) {
|
|
@@ -148,6 +151,17 @@ function validateProperties(obj = {}) {
|
|
|
148
151
|
returnObj[key] = value;
|
|
149
152
|
}
|
|
150
153
|
break;
|
|
154
|
+
case 'expires_at':
|
|
155
|
+
case 'expiresAt':
|
|
156
|
+
if (isValidTimestampzString(value) || isValidTimestampString(value)) {
|
|
157
|
+
returnObj[key] = value;
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case 'active':
|
|
161
|
+
if (isBoolValue(value)) {
|
|
162
|
+
returnObj[key] = value;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
151
165
|
}
|
|
152
166
|
}
|
|
153
167
|
|