-
Notifications
You must be signed in to change notification settings - Fork 109
Description
In “ Implementation of a modular schema
library in TypeScript with focus on bundle
size and performance” (2003; see https://valibot.dev/thesis.pdf), Fabian Hiller presented valibot as an alternative to preexisting validation libraries that could achieve smaller bundle size by optimizing for tree shaking.
Many JavaScript apis such as RxJS, Valibot, Zod, JQuery, deal with the concept of pipelining. Existing approaches are to either:
- expose a fluent API (ex: z.string().email().optional() ) which necessarily pulls in large bits of code (i.e. email validation) for smaller tasks (I.e. simple type assertion of a string).
- use a pipe operator (ex. v.pipe(v.string(), v.email(), v.optional()) ). A Quick Look at npm or GitHub stats shows the popularity of a fluent API over a pipe function.
If support for pipelining were built into the language in a way that its syntax became preferred or even increased popularity of piped apis, it would benefit the ecosystem insofar as tree shakable code leads to smaller bundle sizes and allows libraries to provide more features without requiring consumers to ship unused code.