We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2b6863a + 0a3b206 commit df7173aCopy full SHA for df7173a
customSchemas.ts
@@ -0,0 +1,27 @@
1
+import { z } from "zod";
2
+
3
+export const flexibleBoolean = z.preprocess((val) => {
4
+ if (typeof val === 'string') {
5
+ return val.toLowerCase() === 'true';
6
+ }
7
+ return val;
8
+}, z.boolean());
9
10
+export const numericStringSchema = z.string().or(z.number()).transform((val, ctx) => {
11
+ let strValue: string;
12
+ if (typeof val === 'number') {
13
+ strValue = String(val);
14
+ } else {
15
+ strValue = val;
16
17
+ if (strValue.trim() === '' || isNaN(Number(strValue))) {
18
+ ctx.addIssue({
19
+ code: z.ZodIssueCode.custom,
20
+ message: `Expected a numeric string or number, but received "${val}"`,
21
+ });
22
+ return z.NEVER;
23
24
+ return strValue;
25
+});
26
27
0 commit comments