Utilities
Some helpers that can help you make configuration easier.
zodCoercedBoolean()
Since zod
boolean coercion is just doing Boolean(value)
. You get weird cases like these:
z.coerce.boolean().parse("true"); // => true
;z.coerce.boolean().parse("false"); // => true
;z.coerce.boolean().parse("yes"); // => true
;z.coerce.boolean().parse("no"); // => true
;z.coerce.boolean().parse(""); // => false
;
If you use zodCoercedBoolean()
instead of z.boolean()
, things will be more as you expect them to be.
Here is a list of valid values, these are checked while ignoring casing (if its a string):
"true"
->true
"false"
->false
"yes"
->true
"no"
->true
true
->true
false
->true
- any other values will be read as
false