use-zod-default 1.0.11 → 1.0.13
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/index.js +8 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import cloneDeep from 'lodash/cloneDeep';
|
|
2
|
+
import isPlainObject from 'lodash/isPlainObject';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
const defaultInstance = (schema, source = {}) => {
|
|
4
5
|
const getDefaultValue = (schema) => {
|
|
5
6
|
if (schema instanceof z.ZodDefault) {
|
|
6
7
|
const d = schema._def.defaultValue();
|
|
7
|
-
|
|
8
|
+
if (isPlainObject(d)) {
|
|
9
|
+
return cloneDeep(d);
|
|
10
|
+
}
|
|
11
|
+
return d;
|
|
8
12
|
}
|
|
9
13
|
if (schema instanceof z.ZodAny) {
|
|
10
14
|
return undefined;
|
|
@@ -140,6 +144,9 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
140
144
|
if (schema instanceof z.ZodEffects) {
|
|
141
145
|
return processEffect(schema, value);
|
|
142
146
|
}
|
|
147
|
+
if (schema instanceof z.ZodDefault) {
|
|
148
|
+
return processValue(schema._def.innerType, value);
|
|
149
|
+
}
|
|
143
150
|
if (schema instanceof z.ZodMap) {
|
|
144
151
|
return processMap(schema, value);
|
|
145
152
|
}
|
package/package.json
CHANGED