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 ac53f08 + 19b7254 commit b31ba72Copy full SHA for b31ba72
customSchemas.ts
@@ -15,11 +15,17 @@ const logger = pino({
15
},
16
});
17
18
-export const flexibleBoolean = z.preprocess((val) => {
19
- if (typeof val === 'string') {
20
- return val.toLowerCase() === 'true';
21
- }
+export const flexibleBoolean = z.preprocess(val => {
+ if (typeof val === "boolean") {
22
return val;
+ }
+ let result = "false";
23
+ try {
24
+ result = String(val).toLowerCase();
25
+ } catch {
26
+ return false;
27
28
+ return ["true", "t", "1"].includes(result);
29
}, z.boolean());
30
31
export const flexibleBooleanNullable = DEFAULT_NULL ? flexibleBoolean.nullable().default(null) : flexibleBoolean.nullable();
0 commit comments