Zod is a great library for shaping and validating data. So away from the long introductory, it misses few feature.
People tried to fix its issues with extended libraries.
But since some are not maintained or didn't meet my criteria, here's my fine-tuned version of them.
If something doesn't work, please comment. I might come back, or might not.
A library made to enhance intellisense while defining z
rules.
Not continued, so here you go with my changes.
My changes are for supporting union
, default
and refine
(ZodEffect) rules.
A gist made to build default value based on zod rules.
I struggled with these rules with other utils and validation, so here is my summary. They must come at the end after defining all other rules in this order when any/all are used:
z.string() // or number() or object({}) ...
.nullable() // always comes at last and before optional.
.optional() // always comes at last and before default.
.refine(_=>true) // custom validation after all built-in rules.
.defatul("") // always comes at last.