@travetto/schema 4.1.0 → 4.1.1
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/LICENSE +1 -1
- package/package.json +3 -3
- package/src/data.ts +8 -2
package/LICENSE
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/schema",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "Data type registry for runtime validation, reflection and binding.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"schema",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"directory": "module/schema"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/registry": "^4.1.
|
|
30
|
+
"@travetto/registry": "^4.1.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/transformer": "^4.1.
|
|
33
|
+
"@travetto/transformer": "^4.1.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"@travetto/transformer": {
|
package/src/data.ts
CHANGED
|
@@ -108,9 +108,15 @@ export class DataUtil {
|
|
|
108
108
|
|
|
109
109
|
switch (type) {
|
|
110
110
|
case Date: {
|
|
111
|
-
|
|
111
|
+
let res: Date | undefined;
|
|
112
|
+
if (typeof input === 'object' && 'toDate' in input && typeof input.toDate === 'function') {
|
|
112
113
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
113
|
-
|
|
114
|
+
res = input.toDate() as Date;
|
|
115
|
+
} else {
|
|
116
|
+
res = typeof input === 'number' || /^[-]?\d+$/.test(`${input}`) ?
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
118
|
+
new Date(parseInt(input as string, 10)) : new Date(input as Date);
|
|
119
|
+
}
|
|
114
120
|
if (strict && Number.isNaN(res.getTime())) {
|
|
115
121
|
throw new Error(`Invalid date value: ${input}`);
|
|
116
122
|
}
|