-
Truth. Zod is comparable to JSON Schema plus AJV, and it doesn't compare well at all. Your Zod code is all locked inside TypeScript so not only can it not be shared to any other language in your stack but it also cannot be serialized, which introduces many limitations. You also miss out on all the JSON Schema ecosystem tooling. (1, 2) For example the intellisense you get in VS Code for config files is powered by JSON Schema and schemastore.
-
Civic Auth
Auth in Less Than 5 Minutes. Civic Auth comes with multiple SSO options, optional embedded wallets, and user management — all implemented with just a few lines of code. Start building today.
-
For these reasons I continue to recommend typebox over Zod. I honestly have yet to be given one compelling reason to use Zod over typebox. You'd have to argue against all of those JSON Schema upsides, which immediately undermines the argument. This whole "debate" comes off as "if all you have is a hammer, everything looks like a nail." People just don't know about JSON Schema, its many upsides, its ecosystem, and its tooling.
-
Additionally Zod is also undergoing breaking changes, as any library would. (Example) As a comparison, it seems moot.
-
Oh, and if you're looking for even better security, you should give "Deno" a try. It's another JavaScript runtime that runs programs faster and has an easy way to handle permissions. Plus, it's more secure than Node.js. Here's the link: https://deno.land
-
Also, have you heard of this new JavaScript runtime called "Bun"? Apparently it runs programs even faster than Node.js and automatically installs packages for you. Sounds pretty sweet, right? Here's the link if you want to check it out: https://bun.sh
-
For your particular example though, if we keep in mind that the input data to be validated is JSON-serializable, only a string could possibly accommodate the precision expected of a decimal from among the JSON-serializable JS primitives. You could use one or more regex patterns to describe the allowable permutations. The resultant schema would be cross-platform since it doesn't use custom keywords - nice! You can also use unions if you want to say that integers, NaN, and Infinity are also allowed per the docs there.