Comparing Vest to Other Form Validation Libraries
Vest vs. the Rest
When comparing Vest to other form validation libraries, it's important to understand the different types of libraries available and their respective strengths and weaknesses.
1. Functional Matchers: Functional matchers are the most basic form validation libraries. They consist of functions that return a Boolean value based on whether a value meets certain criteria. While these libraries are essential, they lack the structure required for complex form validation scenarios.
Notable libraries in this category include v8n and validatorjs.
2. Schema Validation: Schema validation libraries extend the concept of functional matchers by allowing developers to specify the shape of the entire dataset. A schema validator ensures that the data conforms to the defined schema. While this provides some structure, it may not be efficient for client-side use, because it requires validating the whole schema while users type into field-by-field. Additionally, describing complex scenarios and handling partial form validation can be challenging with schema validators.
Notable libraries in this category include yup, joi, and zod.
3. Framework-Specific Form State Managers: These libraries have gained popularity in recent years. They integrate with UI frameworks and handle form state, interactions, and validations. While they offer mature solutions for client-side use, they often come with limitations. They are tied to specific frameworks or tech stacks, making it difficult to share validation code across teams or switch frameworks without significant refactoring.
Notable libraries in this category include Formik, Vuelidate, vee-validate, and redux-forms.
How does Vest compare to them?
Features | Vest | Functional Matchers | Schema Validation | Framework-Specific Form State Managers |
---|---|---|---|---|
State Management | Stateful | Manual | Manual | Stateful |
Per Field Validation | Supported | Not supported | Not supported | Supported |
Syntax Style | Declarative | Function calls | Declarative | Declarative |
Code Organization | Separate validation suite | Manual organization | Manual organization | Depends on library |
Framework Agnostic | Yes | Yes | Yes | No |
Flexibility for Framework Switch | High | High | High | Limited |
Code Reusability | High | Medium (It's functions...) | Medium (Requires effort) | Low (Within the UI Framework) |
Example Libraries | - | v8n, validatorjs | yup, joi, zod | Formik, Vuelidate, vee-validate, redux-forms |
Vest is a new breed of form validation library that tries to answer the shortcomings of existing solutions, while not compromising on developer experience, user experience and performance. Here's how Vest stands out:
-
Stateful: Vest manages the state of validated fields internally, eliminating the need for developers to manually track field states. It takes care of merging states and handling interactivity seamlessly.
-
Selective Field Validation: Vest allows developers to run validations only on specific fields upon interaction. This eliminates the need to exclude untouched fields from validation results.
-
Simple and Declarative Syntax: Vest adopts a straightforward, unit-test-like syntax that is easy to read, write, and maintain. This simplicity enhances developer productivity.
-
Separate Validation Suite: Vest keeps the validation code separate from the feature code, enabling better code organization and decoupling. This separation promotes code reuse and maintainability.
-
Framework Agnostic: Vest is designed to be framework agnostic, allowing developers to reuse Vest validations across teams and different parts of their products. It provides the flexibility to rewrite the entire application with a different framework without needing to modify the validation code.
With its emphasis on improved developer experience, user experience, and performance, Vest offers a compelling alternative to existing form validation libraries.