use-zod-default 1.0.17 → 1.0.19
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/dist/v4.js +24 -0
- package/package.json +8 -6
package/dist/v4.js
CHANGED
|
@@ -29,6 +29,18 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
29
29
|
if (schema instanceof z.ZodDate) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
+
if (schema instanceof z.ZodISODate) {
|
|
33
|
+
return new Date().toISOString().split('T')[0];
|
|
34
|
+
}
|
|
35
|
+
if (schema instanceof z.ZodISODateTime) {
|
|
36
|
+
return new Date().toISOString();
|
|
37
|
+
}
|
|
38
|
+
if (schema instanceof z.ZodISODuration) {
|
|
39
|
+
return 'P0D';
|
|
40
|
+
}
|
|
41
|
+
if (schema instanceof z.ZodISOTime) {
|
|
42
|
+
return new Date().toISOString().split('T')[1];
|
|
43
|
+
}
|
|
32
44
|
if (schema instanceof z.ZodDiscriminatedUnion) {
|
|
33
45
|
const firstOption = schema._zod.def.options[0];
|
|
34
46
|
return defaultInstance(cast(firstOption));
|
|
@@ -159,6 +171,18 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
159
171
|
if (schema instanceof z.ZodDefault) {
|
|
160
172
|
return processValue(cast(schema._zod.def.innerType), value);
|
|
161
173
|
}
|
|
174
|
+
if (schema instanceof z.ZodISODate) {
|
|
175
|
+
return isString(value) ? value : new Date().toISOString().split('T')[0];
|
|
176
|
+
}
|
|
177
|
+
if (schema instanceof z.ZodISODateTime) {
|
|
178
|
+
return isString(value) ? value : new Date().toISOString();
|
|
179
|
+
}
|
|
180
|
+
if (schema instanceof z.ZodISODuration) {
|
|
181
|
+
return isString(value) ? value : 'P0D';
|
|
182
|
+
}
|
|
183
|
+
if (schema instanceof z.ZodISOTime) {
|
|
184
|
+
return isString(value) ? value : new Date().toISOString().split('T')[1];
|
|
185
|
+
}
|
|
162
186
|
if (schema instanceof z.ZodMap) {
|
|
163
187
|
return processMap(schema, value);
|
|
164
188
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"dependencies": {
|
|
3
|
-
"lodash": "^4.17.21",
|
|
4
|
-
"zod": "^4.0.15"
|
|
5
|
-
},
|
|
6
2
|
"devDependencies": {
|
|
7
3
|
"@types/lodash": "^4.17.12",
|
|
8
4
|
"@types/node": "^22.7.7",
|
|
9
5
|
"@vitest/coverage-v8": "^3.0.5",
|
|
10
6
|
"eslint": "^9.26.0",
|
|
7
|
+
"lodash": "^4.17.21",
|
|
11
8
|
"prettier": "^3.3.3",
|
|
12
9
|
"tsx": "^4.20.3",
|
|
13
10
|
"typescript": "^5.6.3",
|
|
14
11
|
"typescript-eslint": "^8.32.1",
|
|
15
|
-
"vitest": "^2.1.3"
|
|
12
|
+
"vitest": "^2.1.3",
|
|
13
|
+
"zod": "^4.0.17"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"lodash": "^4.17.21",
|
|
17
|
+
"zod": "^4.0.17"
|
|
16
18
|
},
|
|
17
19
|
"exports": {
|
|
18
20
|
".": "./dist/v4.js",
|
|
@@ -36,5 +38,5 @@
|
|
|
36
38
|
"test": "vitest",
|
|
37
39
|
"test:coverage": "rm -rf coverage && vitest --run --coverage"
|
|
38
40
|
},
|
|
39
|
-
"version": "1.0.
|
|
41
|
+
"version": "1.0.19"
|
|
40
42
|
}
|