Search

Zod to Validbot: Can the library billed as < 1 KB hold up?

While I’m on a thread here, here’s another thing you’re definitely going to do in your web development career: validate some data.

I just linked up some stuff about form validation, for instance. TypeScript can be a part of this process. There is some degree of data safety in your application by virtue of strictly checking types at the code level. But there are limits to that. TypeScript types are only checked at build time, so if data gets into the system some unexpected way during use, TypeScript isn’t going to be telling you about it. Plus, data types is a pretty basic level of validation. You might need to validate that a date is at least 5 days in the future, or that a number is between 0 and 100, and you might really only be able to do it at runtime, when you actually have data to test against.

In the last year or so, we’ve seen Zod become a pretty popular choice for this. While it’s great client-side, Astro cleverly uses it during build to validate data during a site build. Zod is also around 14 KB minified, so a small but non-trivial add to client-side bundles. Validbot, a newcomer alternative, is quite a bit smaller, thanks to being full tree-shakeable (unused functions not included in bundle) making most usage closer to 1 KB. Matthew Wang Shun has an article about switching that is largely positive.

Need front-end development training?

Frontend Masters logo

Frontend Masters is the best place to grow in your career as a developer. We have courses on all the most important front-end technologies and beyond, from React to CSS, to backend with Node.js and Full Stack.

Leave a Reply

Your email address will not be published. Required fields are marked *

Frontend Masters ❤️ Open Source

Did you know? Frontend Masters Donates to open source projects. $313,806 contributed to date.