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.
Files changed (2) hide show
  1. package/dist/index.js +8 -1
  2. 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
- return cloneDeep(d);
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
@@ -30,5 +30,5 @@
30
30
  "test": "vitest",
31
31
  "test:coverage": "rm -rf coverage && vitest --run --coverage"
32
32
  },
33
- "version": "1.0.11"
33
+ "version": "1.0.13"
34
34
  }