@hy_ong/zod-kit 0.0.2 → 0.0.4
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/README.md +2 -2
- package/dist/index.cjs +117 -117
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +117 -117
- package/package.json +3 -3
- package/src/common/boolean.ts +4 -5
- package/src/common/date.ts +5 -6
- package/src/common/email.ts +10 -11
- package/src/common/integer.ts +7 -8
- package/src/common/number.ts +6 -7
- package/src/common/password.ts +8 -9
- package/src/common/text.ts +8 -9
- package/src/common/url.ts +9 -10
- package/src/i18n/locales/en.json +44 -44
- package/src/i18n/locales/zh-TW.json +41 -41
- package/tests/common/boolean.test.ts +20 -20
- package/tests/common/email.test.ts +20 -20
- package/tests/common/integer.test.ts +18 -18
- package/tests/common/number.test.ts +14 -14
- package/tests/common/password.test.ts +23 -23
- package/tests/common/text.test.ts +23 -23
- package/tests/common/url.test.ts +17 -17
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ npm install zod-kit
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import { email, password, text, number } from 'zod-kit'
|
|
22
|
+
import { email, password, text, number } from '@hy_ong/zod-kit'
|
|
23
23
|
|
|
24
24
|
// Email validation
|
|
25
25
|
const emailSchema = email({ label: 'Email' })
|
|
@@ -137,7 +137,7 @@ boolean({
|
|
|
137
137
|
Set the locale for error messages:
|
|
138
138
|
|
|
139
139
|
```typescript
|
|
140
|
-
import { setLocale } from 'zod-kit'
|
|
140
|
+
import { setLocale } from '@hy_ong/zod-kit'
|
|
141
141
|
|
|
142
142
|
// Set to English (default is Traditional Chinese)
|
|
143
143
|
setLocale('en')
|
package/dist/index.cjs
CHANGED
|
@@ -39,65 +39,65 @@ var import_zod = require("zod");
|
|
|
39
39
|
var zh_TW_default = {
|
|
40
40
|
common: {
|
|
41
41
|
boolean: {
|
|
42
|
-
required: "\
|
|
42
|
+
required: "\u5FC5\u586B",
|
|
43
43
|
shouldBe: {
|
|
44
|
-
true: "
|
|
45
|
-
false: "
|
|
44
|
+
true: "\u5FC5\u9808\u70BA\u662F",
|
|
45
|
+
false: "\u5FC5\u9808\u70BA\u5426"
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
email: {
|
|
49
|
-
required: "\
|
|
50
|
-
min: "
|
|
51
|
-
max: "
|
|
52
|
-
includes: "
|
|
53
|
-
invalid: "
|
|
54
|
-
domain: "
|
|
49
|
+
required: "\u5FC5\u586B",
|
|
50
|
+
min: "\u9577\u5EA6\u81F3\u5C11 ${min} \u5B57\u5143",
|
|
51
|
+
max: "\u9577\u5EA6\u6700\u591A ${max} \u5B57\u5143",
|
|
52
|
+
includes: "\u5FC5\u9808\u5305\u542B\u300C${includes}\u300D",
|
|
53
|
+
invalid: "\u683C\u5F0F\u932F\u8AA4",
|
|
54
|
+
domain: "\u5FC5\u9808\u70BA @${domain} \u7DB2\u57DF"
|
|
55
55
|
},
|
|
56
56
|
url: {
|
|
57
|
-
required: "\
|
|
58
|
-
min: "
|
|
59
|
-
max: "
|
|
60
|
-
includes: "
|
|
61
|
-
invalid: "
|
|
57
|
+
required: "\u5FC5\u586B",
|
|
58
|
+
min: "\u9577\u5EA6\u81F3\u5C11 ${min} \u5B57\u5143",
|
|
59
|
+
max: "\u9577\u5EA6\u6700\u591A ${max} \u5B57\u5143",
|
|
60
|
+
includes: "\u5FC5\u9808\u5305\u542B\u300C${includes}\u300D",
|
|
61
|
+
invalid: "\u683C\u5F0F\u932F\u8AA4"
|
|
62
62
|
},
|
|
63
63
|
password: {
|
|
64
|
-
required: "\
|
|
65
|
-
min: "
|
|
66
|
-
max: "
|
|
67
|
-
uppercase: "
|
|
68
|
-
lowercase: "
|
|
69
|
-
digits: "
|
|
70
|
-
special: "
|
|
64
|
+
required: "\u5FC5\u586B",
|
|
65
|
+
min: "\u9577\u5EA6\u81F3\u5C11 ${min} \u5B57\u5143",
|
|
66
|
+
max: "\u9577\u5EA6\u6700\u591A ${max} \u5B57\u5143",
|
|
67
|
+
uppercase: "\u5FC5\u9808\u5305\u542B\u81F3\u5C11\u4E00\u500B\u5927\u5BEB\u5B57\u6BCD",
|
|
68
|
+
lowercase: "\u5FC5\u9808\u5305\u542B\u81F3\u5C11\u4E00\u500B\u5C0F\u5BEB\u5B57\u6BCD",
|
|
69
|
+
digits: "\u5FC5\u9808\u5305\u542B\u81F3\u5C11\u4E00\u500B\u6578\u5B57",
|
|
70
|
+
special: "\u5FC5\u9808\u5305\u542B\u81F3\u5C11\u4E00\u500B\u7279\u6B8A\u7B26\u865F"
|
|
71
71
|
},
|
|
72
72
|
number: {
|
|
73
|
-
required: "\
|
|
74
|
-
min: "
|
|
75
|
-
max: "
|
|
73
|
+
required: "\u5FC5\u586B",
|
|
74
|
+
min: "\u6700\u5C0F\u503C ${min}",
|
|
75
|
+
max: "\u6700\u5927\u503C ${max}"
|
|
76
76
|
},
|
|
77
77
|
id: {
|
|
78
|
-
required: "\u8ACB\u9078\u64C7
|
|
79
|
-
invalid: "
|
|
78
|
+
required: "\u8ACB\u9078\u64C7",
|
|
79
|
+
invalid: "\u7121\u6548"
|
|
80
80
|
},
|
|
81
81
|
integer: {
|
|
82
|
-
required: "\
|
|
83
|
-
min: "
|
|
84
|
-
max: "
|
|
85
|
-
integer: "
|
|
82
|
+
required: "\u5FC5\u586B",
|
|
83
|
+
min: "\u6700\u5C0F\u503C ${min}",
|
|
84
|
+
max: "\u6700\u5927\u503C ${max}",
|
|
85
|
+
integer: "\u5FC5\u9808\u70BA\u6574\u6578"
|
|
86
86
|
},
|
|
87
87
|
float: {
|
|
88
|
-
required: "\
|
|
89
|
-
float: "
|
|
90
|
-
min: "
|
|
91
|
-
max: "
|
|
88
|
+
required: "\u5FC5\u586B",
|
|
89
|
+
float: "\u5FC5\u9808\u70BA\u6D6E\u9EDE\u6578",
|
|
90
|
+
min: "\u6700\u5C0F\u503C ${min}",
|
|
91
|
+
max: "\u6700\u5927\u503C ${max}"
|
|
92
92
|
},
|
|
93
93
|
text: {
|
|
94
|
-
required: "\
|
|
95
|
-
min: "
|
|
96
|
-
max: "
|
|
97
|
-
startsWith: "
|
|
98
|
-
endsWith: "
|
|
99
|
-
includes: "
|
|
100
|
-
invalid: "
|
|
94
|
+
required: "\u5FC5\u586B",
|
|
95
|
+
min: "\u9577\u5EA6\u81F3\u5C11 ${min} \u5B57\u5143",
|
|
96
|
+
max: "\u9577\u5EA6\u6700\u591A ${max} \u5B57\u5143",
|
|
97
|
+
startsWith: "\u5FC5\u9808\u4EE5\u300C${startsWith}\u300D\u958B\u982D",
|
|
98
|
+
endsWith: "\u5FC5\u9808\u4EE5\u300C${endsWith}\u300D\u7D50\u5C3E",
|
|
99
|
+
includes: "\u5FC5\u9808\u5305\u542B\u300C${includes}\u300D",
|
|
100
|
+
invalid: "\u683C\u5F0F\u932F\u8AA4"
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
};
|
|
@@ -106,68 +106,68 @@ var zh_TW_default = {
|
|
|
106
106
|
var en_default = {
|
|
107
107
|
common: {
|
|
108
108
|
boolean: {
|
|
109
|
-
required: "
|
|
109
|
+
required: "Required",
|
|
110
110
|
shouldBe: {
|
|
111
|
-
true: "
|
|
112
|
-
false: "
|
|
111
|
+
true: "Must be True",
|
|
112
|
+
false: "Must be False"
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
115
|
email: {
|
|
116
|
-
required: "
|
|
117
|
-
min: "
|
|
118
|
-
max: "
|
|
119
|
-
includes: "
|
|
120
|
-
invalid: "
|
|
121
|
-
domain: "
|
|
116
|
+
required: "Required",
|
|
117
|
+
min: "Must be at least ${min} characters",
|
|
118
|
+
max: "Must be at most ${max} characters",
|
|
119
|
+
includes: "Must include ${includes}",
|
|
120
|
+
invalid: "Invalid format",
|
|
121
|
+
domain: "Must be under the domain @${domain}"
|
|
122
122
|
},
|
|
123
123
|
url: {
|
|
124
|
-
required: "
|
|
125
|
-
min: "
|
|
126
|
-
max: "
|
|
127
|
-
includes: "
|
|
128
|
-
invalid: "
|
|
124
|
+
required: "Required",
|
|
125
|
+
min: "Must be at least ${min} characters",
|
|
126
|
+
max: "Must be at most ${max} characters",
|
|
127
|
+
includes: "Must include ${includes}",
|
|
128
|
+
invalid: "Invalid format"
|
|
129
129
|
},
|
|
130
130
|
password: {
|
|
131
|
-
required: "
|
|
132
|
-
min: "
|
|
133
|
-
max: "
|
|
134
|
-
uppercase: "
|
|
135
|
-
lowercase: "
|
|
136
|
-
digits: "
|
|
137
|
-
special: "
|
|
131
|
+
required: "Required",
|
|
132
|
+
min: "Must be at least ${min} characters",
|
|
133
|
+
max: "Must be at most ${max} characters",
|
|
134
|
+
uppercase: "Must include at least one uppercase letter",
|
|
135
|
+
lowercase: "Must include at least one lowercase letter",
|
|
136
|
+
digits: "Must include at least one digit",
|
|
137
|
+
special: "Must include at least one special character"
|
|
138
138
|
},
|
|
139
139
|
number: {
|
|
140
|
-
required: "
|
|
141
|
-
min: "
|
|
142
|
-
max: "
|
|
140
|
+
required: "Required",
|
|
141
|
+
min: "Must be at least ${min}",
|
|
142
|
+
max: "Must be at most ${max}"
|
|
143
143
|
},
|
|
144
144
|
integer: {
|
|
145
|
-
required: "
|
|
146
|
-
min: "
|
|
147
|
-
max: "
|
|
148
|
-
integer: "
|
|
145
|
+
required: "Required",
|
|
146
|
+
min: "Must be at least ${min}",
|
|
147
|
+
max: "Must be at most ${max}",
|
|
148
|
+
integer: "Must be an integer"
|
|
149
149
|
},
|
|
150
150
|
float: {
|
|
151
|
-
required: "
|
|
152
|
-
min: "
|
|
153
|
-
max: "
|
|
154
|
-
float: "
|
|
151
|
+
required: "Required",
|
|
152
|
+
min: "Must be at least ${min}",
|
|
153
|
+
max: "Must be at most ${max}",
|
|
154
|
+
float: "Must be an float"
|
|
155
155
|
},
|
|
156
156
|
text: {
|
|
157
|
-
required: "
|
|
158
|
-
min: "
|
|
159
|
-
max: "
|
|
160
|
-
startsWith: "
|
|
161
|
-
endsWith: "
|
|
162
|
-
includes: "
|
|
163
|
-
invalid: "
|
|
157
|
+
required: "Required",
|
|
158
|
+
min: "Must be at least ${min} characters",
|
|
159
|
+
max: "Must be at most ${max} characters",
|
|
160
|
+
startsWith: "Must start with ${startsWith}",
|
|
161
|
+
endsWith: "Must end with ${endsWith}",
|
|
162
|
+
includes: "Must include ${includes}",
|
|
163
|
+
invalid: "Invalid format"
|
|
164
164
|
},
|
|
165
165
|
date: {
|
|
166
|
-
required: "
|
|
167
|
-
min: "
|
|
168
|
-
max: "
|
|
169
|
-
includes: "
|
|
170
|
-
format: "
|
|
166
|
+
required: "Required",
|
|
167
|
+
min: "Must be at least ${min} characters",
|
|
168
|
+
max: "Must be at most ${max} characters",
|
|
169
|
+
includes: "Must include ${includes}",
|
|
170
|
+
format: "Must be in ${format} format"
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
};
|
|
@@ -197,7 +197,7 @@ function getNestedValue(obj, path) {
|
|
|
197
197
|
|
|
198
198
|
// src/common/boolean.ts
|
|
199
199
|
function boolean(options) {
|
|
200
|
-
const { required = true,
|
|
200
|
+
const { required = true, defaultValue = null, shouldBe } = options ?? {};
|
|
201
201
|
let result = import_zod.z.preprocess(
|
|
202
202
|
(val) => {
|
|
203
203
|
if (val === "" || val === void 0 || val === null) return defaultValue;
|
|
@@ -208,12 +208,12 @@ function boolean(options) {
|
|
|
208
208
|
import_zod.z.union([import_zod.z.literal(true), import_zod.z.literal(false), import_zod.z.literal(null)])
|
|
209
209
|
);
|
|
210
210
|
if (required && defaultValue === null) {
|
|
211
|
-
result = result.refine((val) => val !== null, { message: t("common.boolean.required"
|
|
211
|
+
result = result.refine((val) => val !== null, { message: t("common.boolean.required") });
|
|
212
212
|
}
|
|
213
213
|
if (shouldBe === true) {
|
|
214
|
-
result = result.refine((val) => val === true, { message: t("common.boolean.shouldBe.true"
|
|
214
|
+
result = result.refine((val) => val === true, { message: t("common.boolean.shouldBe.true") });
|
|
215
215
|
} else if (shouldBe === false) {
|
|
216
|
-
result = result.refine((val) => val === false, { message: t("common.boolean.shouldBe.false"
|
|
216
|
+
result = result.refine((val) => val === false, { message: t("common.boolean.shouldBe.false") });
|
|
217
217
|
}
|
|
218
218
|
return result;
|
|
219
219
|
}
|
|
@@ -221,23 +221,23 @@ function boolean(options) {
|
|
|
221
221
|
// src/common/email.ts
|
|
222
222
|
var import_zod2 = require("zod");
|
|
223
223
|
function email(options) {
|
|
224
|
-
const { required = true,
|
|
224
|
+
const { required = true, domain, min, max, includes } = options ?? {};
|
|
225
225
|
const baseSchema = required ? import_zod2.z.preprocess(
|
|
226
226
|
(val) => val === "" || val === null || val === void 0 ? null : val,
|
|
227
227
|
import_zod2.z.email({
|
|
228
228
|
error: (issue) => {
|
|
229
|
-
if (issue.code === "invalid_type") return t("common.email.required"
|
|
230
|
-
else if (issue.code === "invalid_format") return t("common.email.invalid"
|
|
231
|
-
return t("common.email.invalid"
|
|
229
|
+
if (issue.code === "invalid_type") return t("common.email.required");
|
|
230
|
+
else if (issue.code === "invalid_format") return t("common.email.invalid");
|
|
231
|
+
return t("common.email.invalid");
|
|
232
232
|
}
|
|
233
233
|
})
|
|
234
|
-
) : import_zod2.z.preprocess((val) => val === "" || val === null || val === void 0 ? null : val, import_zod2.z.email({ message: t("common.email.invalid"
|
|
235
|
-
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.text.required"
|
|
234
|
+
) : import_zod2.z.preprocess((val) => val === "" || val === null || val === void 0 ? null : val, import_zod2.z.email({ message: t("common.email.invalid") }).nullable());
|
|
235
|
+
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.text.required") }).refine((val) => val === null || min === void 0 || val.length >= min, { message: t("common.text.min", { min }) }).refine((val) => val === null || max === void 0 || val.length <= max, { message: t("common.text.max", { max }) }).refine((val) => val === null || includes === void 0 || val.includes(includes), { message: t("common.text.includes", { includes }) }).refine(
|
|
236
236
|
(val) => {
|
|
237
237
|
if (val === null || domain === void 0) return true;
|
|
238
238
|
return val.split("@")[1]?.toLowerCase() === domain.toLowerCase();
|
|
239
239
|
},
|
|
240
|
-
{ message: t("common.email.domain", {
|
|
240
|
+
{ message: t("common.email.domain", { domain }) }
|
|
241
241
|
);
|
|
242
242
|
return schema;
|
|
243
243
|
}
|
|
@@ -245,34 +245,34 @@ function email(options) {
|
|
|
245
245
|
// src/common/url.ts
|
|
246
246
|
var import_zod3 = require("zod");
|
|
247
247
|
function url(options) {
|
|
248
|
-
const { required = true,
|
|
248
|
+
const { required = true, min, max, includes } = options ?? {};
|
|
249
249
|
const baseSchema = required ? import_zod3.z.preprocess(
|
|
250
250
|
(val) => val === "" || val === null || val === void 0 ? null : val,
|
|
251
251
|
import_zod3.z.url({
|
|
252
252
|
error: (issue) => {
|
|
253
|
-
if (issue.code === "invalid_type") return t("common.url.required"
|
|
254
|
-
else if (issue.code === "invalid_format") return t("common.url.invalid"
|
|
255
|
-
return t("common.url.invalid"
|
|
253
|
+
if (issue.code === "invalid_type") return t("common.url.required");
|
|
254
|
+
else if (issue.code === "invalid_format") return t("common.url.invalid");
|
|
255
|
+
return t("common.url.invalid");
|
|
256
256
|
}
|
|
257
257
|
})
|
|
258
|
-
) : import_zod3.z.preprocess((val) => val === "" || val === null || val === void 0 ? null : val, import_zod3.z.url({ message: t("common.url.invalid"
|
|
259
|
-
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.text.required"
|
|
258
|
+
) : import_zod3.z.preprocess((val) => val === "" || val === null || val === void 0 ? null : val, import_zod3.z.url({ message: t("common.url.invalid") }).nullable());
|
|
259
|
+
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.text.required") }).refine((val) => val === null || min === void 0 || val.length >= min, { message: t("common.text.min", { min }) }).refine((val) => val === null || max === void 0 || val.length <= max, { message: t("common.text.max", { max }) }).refine((val) => val === null || includes === void 0 || val.includes(includes), { message: t("common.text.includes", { includes }) });
|
|
260
260
|
return schema;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
// src/common/text.ts
|
|
264
264
|
var import_zod4 = require("zod");
|
|
265
265
|
function text(options) {
|
|
266
|
-
const { required = true,
|
|
266
|
+
const { required = true, min, max, startsWith, endsWith, includes, regex, defaultValue = null } = options ?? {};
|
|
267
267
|
const baseSchema = required ? import_zod4.z.preprocess((val) => val === "" || val === null || val === void 0 ? defaultValue : val, import_zod4.z.coerce.string().trim()) : import_zod4.z.preprocess((val) => val === "" || val === null || val === void 0 ? defaultValue : val, import_zod4.z.coerce.string().trim().nullable());
|
|
268
|
-
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.text.required"
|
|
268
|
+
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.text.required") }).refine((val) => val === null || min === void 0 || val.length >= min, { message: t("common.text.min", { min }) }).refine((val) => val === null || max === void 0 || val.length <= max, { message: t("common.text.max", { max }) }).refine((val) => val === null || startsWith === void 0 || val.startsWith(startsWith), { message: t("common.text.startsWith", { startsWith }) }).refine((val) => val === null || endsWith === void 0 || val.endsWith(endsWith), { message: t("common.text.endsWith", { endsWith }) }).refine((val) => val === null || includes === void 0 || val.includes(includes), { message: t("common.text.includes", { includes }) }).refine((val) => val === null || regex === void 0 || regex.test(val), { message: t("common.text.invalid", { regex }) });
|
|
269
269
|
return schema;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
// src/common/number.ts
|
|
273
273
|
var import_zod5 = require("zod");
|
|
274
274
|
function number(options) {
|
|
275
|
-
const { required = true,
|
|
275
|
+
const { required = true, min, max, defaultValue } = options ?? {};
|
|
276
276
|
const schema = import_zod5.z.preprocess(
|
|
277
277
|
(val) => {
|
|
278
278
|
if (val === "" || val === void 0 || val === null) return defaultValue ?? null;
|
|
@@ -281,29 +281,29 @@ function number(options) {
|
|
|
281
281
|
import_zod5.z.union([
|
|
282
282
|
import_zod5.z.number({
|
|
283
283
|
error: (issue) => {
|
|
284
|
-
if (issue.code === "invalid_type") return t("common.number.integer"
|
|
285
|
-
return t("common.number.required"
|
|
284
|
+
if (issue.code === "invalid_type") return t("common.number.integer");
|
|
285
|
+
return t("common.number.required");
|
|
286
286
|
}
|
|
287
287
|
}),
|
|
288
288
|
import_zod5.z.null()
|
|
289
289
|
])
|
|
290
|
-
).refine((val) => !required || val !== null, { message: t("common.number.required"
|
|
290
|
+
).refine((val) => !required || val !== null, { message: t("common.number.required") }).refine((val) => val === null || min === void 0 || val >= min, { message: t("common.number.min", { min }) }).refine((val) => val === null || max === void 0 || val <= max, { message: t("common.number.max", { max }) });
|
|
291
291
|
return schema;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
// src/common/password.ts
|
|
295
295
|
var import_zod6 = require("zod");
|
|
296
296
|
function password(options) {
|
|
297
|
-
const { required = true,
|
|
297
|
+
const { required = true, min, max, uppercase, lowercase, digits, special } = options ?? {};
|
|
298
298
|
const baseSchema = required ? import_zod6.z.preprocess((val) => val === "" || val === null || val === void 0 ? null : val, import_zod6.z.coerce.string().trim()) : import_zod6.z.preprocess((val) => val === "" || val === null || val === void 0 ? null : val, import_zod6.z.coerce.string().trim().nullable());
|
|
299
|
-
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.password.required"
|
|
299
|
+
const schema = baseSchema.refine((val) => required ? val !== "" && val !== "null" && val !== "undefined" : true, { message: t("common.password.required") }).refine((val) => val === null || min === void 0 || val.length >= min, { message: t("common.password.min", { min }) }).refine((val) => val === null || max === void 0 || val.length <= max, { message: t("common.password.max", { max }) }).refine((val) => val === null || !uppercase || /[A-Z]/.test(val), { message: t("common.password.uppercase") }).refine((val) => val === null || !lowercase || /[a-z]/.test(val), { message: t("common.password.lowercase") }).refine((val) => val === null || !special || /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]+/.test(val), { message: t("common.password.special") }).refine((val) => val === null || !digits || /[0-9]/.test(val), { message: t("common.password.digits") });
|
|
300
300
|
return schema;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
// src/common/integer.ts
|
|
304
304
|
var import_zod7 = require("zod");
|
|
305
305
|
function integer(options) {
|
|
306
|
-
const { required = true,
|
|
306
|
+
const { required = true, min, max, defaultValue } = options ?? {};
|
|
307
307
|
const schema = import_zod7.z.preprocess(
|
|
308
308
|
(val) => {
|
|
309
309
|
if (val === "" || val === void 0 || val === null) return defaultValue ?? null;
|
|
@@ -312,20 +312,20 @@ function integer(options) {
|
|
|
312
312
|
import_zod7.z.union([
|
|
313
313
|
import_zod7.z.number({
|
|
314
314
|
error: (issue) => {
|
|
315
|
-
if (issue.code === "invalid_type") return t("common.integer.integer"
|
|
316
|
-
return t("common.integer.required"
|
|
315
|
+
if (issue.code === "invalid_type") return t("common.integer.integer");
|
|
316
|
+
return t("common.integer.required");
|
|
317
317
|
}
|
|
318
318
|
}),
|
|
319
319
|
import_zod7.z.null()
|
|
320
320
|
])
|
|
321
321
|
).refine((val) => !required || val !== null, {
|
|
322
|
-
message: t("common.integer.required"
|
|
322
|
+
message: t("common.integer.required")
|
|
323
323
|
}).refine((val) => val === null || Number.isInteger(val), {
|
|
324
|
-
message: t("common.integer.integer"
|
|
324
|
+
message: t("common.integer.integer")
|
|
325
325
|
}).refine((val) => val === null || min === void 0 || val >= min, {
|
|
326
|
-
message: t("common.integer.min", {
|
|
326
|
+
message: t("common.integer.min", { min })
|
|
327
327
|
}).refine((val) => val === null || max === void 0 || val <= max, {
|
|
328
|
-
message: t("common.integer.max", {
|
|
328
|
+
message: t("common.integer.max", { max })
|
|
329
329
|
});
|
|
330
330
|
return schema;
|
|
331
331
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,6 @@ import { ZodBoolean, ZodNullable, ZodString, ZodNumber } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
type BooleanOptions<IsRequired extends boolean = true> = {
|
|
4
4
|
required?: IsRequired;
|
|
5
|
-
label: string;
|
|
6
5
|
defaultValue?: IsRequired extends true ? boolean : boolean | null;
|
|
7
6
|
shouldBe?: boolean;
|
|
8
7
|
};
|
|
@@ -11,7 +10,6 @@ declare function boolean<IsRequired extends boolean = true>(options?: BooleanOpt
|
|
|
11
10
|
|
|
12
11
|
type EmailOptions<IsRequired extends boolean = true> = {
|
|
13
12
|
required?: IsRequired;
|
|
14
|
-
label: string;
|
|
15
13
|
domain?: string;
|
|
16
14
|
min?: number;
|
|
17
15
|
max?: number;
|
|
@@ -22,7 +20,6 @@ declare function email<IsRequired extends boolean = true>(options?: EmailOptions
|
|
|
22
20
|
|
|
23
21
|
type UrlOptions<IsRequired extends boolean = true> = {
|
|
24
22
|
required?: IsRequired;
|
|
25
|
-
label: string;
|
|
26
23
|
min?: number;
|
|
27
24
|
max?: number;
|
|
28
25
|
includes?: string;
|
|
@@ -32,7 +29,6 @@ declare function url<IsRequired extends boolean = true>(options?: UrlOptions<IsR
|
|
|
32
29
|
|
|
33
30
|
type TextOptions<IsRequired extends boolean = true> = {
|
|
34
31
|
required?: IsRequired;
|
|
35
|
-
label: string;
|
|
36
32
|
min?: number;
|
|
37
33
|
max?: number;
|
|
38
34
|
startsWith?: string;
|
|
@@ -46,7 +42,6 @@ declare function text<IsRequired extends boolean = true>(options?: TextOptions<I
|
|
|
46
42
|
|
|
47
43
|
type NumberOptions<IsRequired extends boolean = true> = {
|
|
48
44
|
required?: IsRequired;
|
|
49
|
-
label: string;
|
|
50
45
|
min?: number;
|
|
51
46
|
max?: number;
|
|
52
47
|
defaultValue?: IsRequired extends true ? number : number | null;
|
|
@@ -56,7 +51,6 @@ declare function number<IsRequired extends boolean = true>(options?: NumberOptio
|
|
|
56
51
|
|
|
57
52
|
type PasswordOptions<IsRequired extends boolean = true> = {
|
|
58
53
|
required?: IsRequired;
|
|
59
|
-
label: string;
|
|
60
54
|
min?: number;
|
|
61
55
|
max?: number;
|
|
62
56
|
uppercase?: boolean;
|
|
@@ -69,7 +63,6 @@ declare function password<IsRequired extends boolean = true>(options?: PasswordO
|
|
|
69
63
|
|
|
70
64
|
type IntegerOptions<IsRequired extends boolean = true> = {
|
|
71
65
|
required?: IsRequired;
|
|
72
|
-
label: string;
|
|
73
66
|
min?: number;
|
|
74
67
|
max?: number;
|
|
75
68
|
defaultValue?: IsRequired extends true ? number : number | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { ZodBoolean, ZodNullable, ZodString, ZodNumber } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
type BooleanOptions<IsRequired extends boolean = true> = {
|
|
4
4
|
required?: IsRequired;
|
|
5
|
-
label: string;
|
|
6
5
|
defaultValue?: IsRequired extends true ? boolean : boolean | null;
|
|
7
6
|
shouldBe?: boolean;
|
|
8
7
|
};
|
|
@@ -11,7 +10,6 @@ declare function boolean<IsRequired extends boolean = true>(options?: BooleanOpt
|
|
|
11
10
|
|
|
12
11
|
type EmailOptions<IsRequired extends boolean = true> = {
|
|
13
12
|
required?: IsRequired;
|
|
14
|
-
label: string;
|
|
15
13
|
domain?: string;
|
|
16
14
|
min?: number;
|
|
17
15
|
max?: number;
|
|
@@ -22,7 +20,6 @@ declare function email<IsRequired extends boolean = true>(options?: EmailOptions
|
|
|
22
20
|
|
|
23
21
|
type UrlOptions<IsRequired extends boolean = true> = {
|
|
24
22
|
required?: IsRequired;
|
|
25
|
-
label: string;
|
|
26
23
|
min?: number;
|
|
27
24
|
max?: number;
|
|
28
25
|
includes?: string;
|
|
@@ -32,7 +29,6 @@ declare function url<IsRequired extends boolean = true>(options?: UrlOptions<IsR
|
|
|
32
29
|
|
|
33
30
|
type TextOptions<IsRequired extends boolean = true> = {
|
|
34
31
|
required?: IsRequired;
|
|
35
|
-
label: string;
|
|
36
32
|
min?: number;
|
|
37
33
|
max?: number;
|
|
38
34
|
startsWith?: string;
|
|
@@ -46,7 +42,6 @@ declare function text<IsRequired extends boolean = true>(options?: TextOptions<I
|
|
|
46
42
|
|
|
47
43
|
type NumberOptions<IsRequired extends boolean = true> = {
|
|
48
44
|
required?: IsRequired;
|
|
49
|
-
label: string;
|
|
50
45
|
min?: number;
|
|
51
46
|
max?: number;
|
|
52
47
|
defaultValue?: IsRequired extends true ? number : number | null;
|
|
@@ -56,7 +51,6 @@ declare function number<IsRequired extends boolean = true>(options?: NumberOptio
|
|
|
56
51
|
|
|
57
52
|
type PasswordOptions<IsRequired extends boolean = true> = {
|
|
58
53
|
required?: IsRequired;
|
|
59
|
-
label: string;
|
|
60
54
|
min?: number;
|
|
61
55
|
max?: number;
|
|
62
56
|
uppercase?: boolean;
|
|
@@ -69,7 +63,6 @@ declare function password<IsRequired extends boolean = true>(options?: PasswordO
|
|
|
69
63
|
|
|
70
64
|
type IntegerOptions<IsRequired extends boolean = true> = {
|
|
71
65
|
required?: IsRequired;
|
|
72
|
-
label: string;
|
|
73
66
|
min?: number;
|
|
74
67
|
max?: number;
|
|
75
68
|
defaultValue?: IsRequired extends true ? number : number | null;
|