@reldens/utils 0.32.0 → 0.34.0
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/schema-validator.js +8 -0
- package/lib/shortcuts.js +23 -2
- package/package.json +1 -1
package/lib/schema-validator.js
CHANGED
|
@@ -66,6 +66,14 @@ class SchemaValidator
|
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
68
68
|
break;
|
|
69
|
+
case 'number':
|
|
70
|
+
if(!sc.isInt(obj)){
|
|
71
|
+
if(!sc.isFloat(obj)){
|
|
72
|
+
Logger.debug('Object is not a number.', objectKey, obj, schema);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
69
77
|
case 'int':
|
|
70
78
|
if(!sc.isInt(obj)){
|
|
71
79
|
Logger.debug('Object is not an integer.', objectKey, obj, schema);
|
package/lib/shortcuts.js
CHANGED
|
@@ -62,9 +62,14 @@ class Shortcuts
|
|
|
62
62
|
return 'string' === typeof value;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
isNumber(value)
|
|
66
|
+
{
|
|
67
|
+
return 'number' === typeof value;
|
|
68
|
+
}
|
|
69
|
+
|
|
65
70
|
isInt(value)
|
|
66
71
|
{
|
|
67
|
-
if(
|
|
72
|
+
if(!this.isNumber(value)){
|
|
68
73
|
return false;
|
|
69
74
|
}
|
|
70
75
|
return Number.isInteger(value);
|
|
@@ -72,7 +77,7 @@ class Shortcuts
|
|
|
72
77
|
|
|
73
78
|
isFloat(value)
|
|
74
79
|
{
|
|
75
|
-
if(
|
|
80
|
+
if(!this.isNumber(value)){
|
|
76
81
|
return false;
|
|
77
82
|
}
|
|
78
83
|
return Number(value) === value && 0 !== value % 1;
|
|
@@ -295,6 +300,22 @@ class Shortcuts
|
|
|
295
300
|
return (new Date()).toISOString().slice(0, 19).replace('T', '-').replace(/:/g, '-');
|
|
296
301
|
}
|
|
297
302
|
|
|
303
|
+
formatDate(date, format = 'Y-m-d H:i:s')
|
|
304
|
+
{
|
|
305
|
+
if(!(date instanceof Date)){
|
|
306
|
+
return date;
|
|
307
|
+
}
|
|
308
|
+
let map = {
|
|
309
|
+
Y: date.getFullYear(),
|
|
310
|
+
m: (date.getMonth() + 1).toString().padStart(2, '0'),
|
|
311
|
+
d: date.getDate().toString().padStart(2, '0'),
|
|
312
|
+
H: date.getHours().toString().padStart(2, '0'),
|
|
313
|
+
i: date.getMinutes().toString().padStart(2, '0'),
|
|
314
|
+
s: date.getSeconds().toString().padStart(2, '0')
|
|
315
|
+
};
|
|
316
|
+
return format.replace(/Y|m|d|H|i|s/g, matched => map[matched]);
|
|
317
|
+
}
|
|
318
|
+
|
|
298
319
|
getTime()
|
|
299
320
|
{
|
|
300
321
|
return (new Date()).getTime();
|