use-zod-default 1.0.19 → 1.0.20

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/v4.js +40 -5
  2. package/package.json +6 -5
package/dist/v4.js CHANGED
@@ -23,6 +23,12 @@ const defaultInstance = (schema, source = {}) => {
23
23
  if (schema instanceof z.ZodArray) {
24
24
  return [];
25
25
  }
26
+ if (schema instanceof z.ZodBigInt) {
27
+ if (schema._zod.bag?.minimum && schema._zod.bag?.minimum > 0) {
28
+ return BigInt(schema._zod.bag?.minimum);
29
+ }
30
+ return BigInt(0);
31
+ }
26
32
  if (schema instanceof z.ZodBoolean) {
27
33
  return false;
28
34
  }
@@ -69,8 +75,11 @@ const defaultInstance = (schema, source = {}) => {
69
75
  if (schema instanceof z.ZodNullable) {
70
76
  return null;
71
77
  }
72
- if (schema instanceof z.ZodNumber || schema instanceof z.ZodBigInt) {
73
- return schema._zod.bag?.minimum ?? 0;
78
+ if (schema instanceof z.ZodNumber) {
79
+ if (schema._zod.bag?.minimum && schema._zod.bag?.minimum > 0) {
80
+ return schema._zod.bag?.minimum;
81
+ }
82
+ return 0;
74
83
  }
75
84
  if (schema instanceof z.ZodObject) {
76
85
  return defaultInstance(schema, {});
@@ -80,7 +89,7 @@ const defaultInstance = (schema, source = {}) => {
80
89
  const defaultInValue = getDefaultValue(cast(schema._zod.def.in));
81
90
  return getDefaultValue(cast(schema._zod.def.out), defaultInValue);
82
91
  }
83
- return getDefaultValue(cast(schema._zod.def.in), getDefaultValue(cast(schema._zod.def.out)));
92
+ return getDefaultValue(cast(schema._zod.def.out));
84
93
  }
85
94
  if (schema instanceof z.ZodPromise) {
86
95
  return Promise.resolve(getDefaultValue(cast(schema._zod.def.innerType)));
@@ -91,7 +100,27 @@ const defaultInstance = (schema, source = {}) => {
91
100
  if (schema instanceof z.ZodSet) {
92
101
  return new Set();
93
102
  }
94
- if (schema instanceof z.ZodString) {
103
+ if (schema instanceof z.ZodBase64 ||
104
+ schema instanceof z.ZodBase64URL ||
105
+ schema instanceof z.ZodCIDRv4 ||
106
+ schema instanceof z.ZodCIDRv6 ||
107
+ schema instanceof z.ZodCUID ||
108
+ schema instanceof z.ZodCUID2 ||
109
+ schema instanceof z.ZodCustomStringFormat ||
110
+ schema instanceof z.ZodE164 ||
111
+ schema instanceof z.ZodEmail ||
112
+ schema instanceof z.ZodEmoji ||
113
+ schema instanceof z.ZodGUID ||
114
+ schema instanceof z.ZodIPv4 ||
115
+ schema instanceof z.ZodIPv6 ||
116
+ schema instanceof z.ZodJWT ||
117
+ schema instanceof z.ZodKSUID ||
118
+ schema instanceof z.ZodNanoID ||
119
+ schema instanceof z.ZodString ||
120
+ schema instanceof z.ZodULID ||
121
+ schema instanceof z.ZodURL ||
122
+ schema instanceof z.ZodUUID ||
123
+ schema instanceof z.ZodXID) {
95
124
  return '';
96
125
  }
97
126
  if (schema instanceof z.ZodSymbol) {
@@ -162,6 +191,12 @@ const defaultInstance = (schema, source = {}) => {
162
191
  if (schema instanceof z.ZodArray) {
163
192
  return processArray(schema, value);
164
193
  }
194
+ if (schema instanceof z.ZodBigInt) {
195
+ if (typeof value === 'bigint') {
196
+ return value;
197
+ }
198
+ return typeof value === 'number' ? BigInt(value) : BigInt(0);
199
+ }
165
200
  if (schema instanceof z.ZodBoolean) {
166
201
  return isBoolean(value) ? value : false;
167
202
  }
@@ -189,7 +224,7 @@ const defaultInstance = (schema, source = {}) => {
189
224
  if (schema instanceof z.ZodNullable) {
190
225
  return isNil(value) ? null : processValue(schema._zod.def.innerType, value);
191
226
  }
192
- if (schema instanceof z.ZodNumber || schema instanceof z.ZodBigInt) {
227
+ if (schema instanceof z.ZodNumber) {
193
228
  return isNumber(value) ? value : (schema._zod.bag?.minimum ?? 0);
194
229
  }
195
230
  if (schema instanceof z.ZodObject) {
package/package.json CHANGED
@@ -2,14 +2,14 @@
2
2
  "devDependencies": {
3
3
  "@types/lodash": "^4.17.12",
4
4
  "@types/node": "^22.7.7",
5
- "@vitest/coverage-v8": "^3.0.5",
5
+ "@vitest/coverage-v8": "^3.2.4",
6
6
  "eslint": "^9.26.0",
7
7
  "lodash": "^4.17.21",
8
8
  "prettier": "^3.3.3",
9
9
  "tsx": "^4.20.3",
10
10
  "typescript": "^5.6.3",
11
11
  "typescript-eslint": "^8.32.1",
12
- "vitest": "^2.1.3",
12
+ "vitest": "^3.2.4",
13
13
  "zod": "^4.0.17"
14
14
  },
15
15
  "peerDependencies": {
@@ -34,9 +34,10 @@
34
34
  "scripts": {
35
35
  "build": "rm -rf dist && yarn lint && tsc -p tsconfig.json",
36
36
  "lint": "prettier --write . && eslint . && yarn tsc",
37
- "npm:publish": "yarn test --run && yarn build && yarn version --patch --no-git-tag-version && yarn publish --non-interactive",
38
- "test": "vitest",
37
+ "npm:publish": "yarn test && yarn build && yarn version --patch --no-git-tag-version && yarn publish --non-interactive",
38
+ "test": "vitest --run",
39
+ "test:watch": "vitest",
39
40
  "test:coverage": "rm -rf coverage && vitest --run --coverage"
40
41
  },
41
- "version": "1.0.19"
42
+ "version": "1.0.20"
42
43
  }