API

Utilities#

Some helpers that can help you make configuration easier.

zodCoercedBoolean()#

Since z.coerce.boolean() is just doing `Boolean(value) under the hood. 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
  • "yes" -> true
  • true -> true
  • "false" -> false
  • "no" -> false
  • false -> false
  • any other values will be read as false