Top Related Projects
String validation
Dead simple Object schema validation
TypeScript-first schema validation with static type inference
The most powerful data validation library for JS
Decorator-based property validation for classes.
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Quick Overview
Vest is a lightweight JavaScript validation framework designed for complex forms and data structures. It offers a declarative approach to validation, allowing developers to define validation rules in a clear and organized manner. Vest supports asynchronous validations and provides a suite of built-in validation functions.
Pros
- Flexible and extensible, allowing custom validation rules
- Supports both synchronous and asynchronous validations
- Provides detailed validation results, including field-specific errors
- Lightweight and has no dependencies
Cons
- Learning curve for developers new to declarative validation approaches
- Limited built-in localization support
- May require additional setup for complex validation scenarios
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Basic validation suite:
import { create, test, enforce } from 'vest';
const suite = create((data = {}) => {
test('username', 'Username is required', () => {
enforce(data.username).isNotEmpty();
});
test('email', 'Email must be valid', () => {
enforce(data.email).isEmail();
});
});
- Asynchronous validation:
import { create, test, enforce } from 'vest';
const suite = create((data = {}) => {
test('username', 'Username must be unique', async () => {
const isUnique = await checkUsernameUniqueness(data.username);
enforce(isUnique).isTruthy();
});
});
- Custom validation function:
import { create, test, enforce } from 'vest';
enforce.extend({ isValidPostalCode: (value) => /^\d{5}(-\d{4})?$/.test(value) });
const suite = create((data = {}) => {
test('postalCode', 'Invalid postal code', () => {
enforce(data.postalCode).isValidPostalCode();
});
});
Getting Started
To use Vest in your project, first install it via npm:
npm install vest
Then, create a validation suite:
import { create, test, enforce } from 'vest';
const validationSuite = create((data = {}) => {
test('name', 'Name is required', () => {
enforce(data.name).isNotEmpty();
});
test('email', 'Email must be valid', () => {
enforce(data.email).isEmail();
});
});
// Run the validation
const result = validationSuite({ name: 'John', email: 'john@example.com' });
console.log(result.hasErrors()); // false
Competitor Comparisons
String validation
Pros of validator.js
- Extensive library of built-in validation rules
- Supports string validation for URLs, emails, and more
- Well-established project with a large community
Cons of validator.js
- Limited to string validation only
- Lacks support for complex, nested object validation
- No built-in state management for form validation
Code Comparison
validator.js:
import validator from 'validator';
const isValid = validator.isEmail('test@example.com');
console.log(isValid); // true
Vest:
import { create, test, enforce } from 'vest';
const suite = create((data = {}) => {
test('email', 'Email is invalid', () => {
enforce(data.email).isEmail();
});
});
const result = suite({ email: 'test@example.com' });
console.log(result.hasErrors()); // false
Vest offers a more comprehensive approach to form validation, allowing for complex validation logic and state management. validator.js, on the other hand, provides a simpler API focused on string validation. While validator.js excels in its extensive library of string validation rules, Vest's flexibility and support for object validation make it more suitable for complex form validation scenarios.
Dead simple Object schema validation
Pros of Yup
- More mature and widely adopted in the React ecosystem
- Supports asynchronous validation out of the box
- Offers a wider range of built-in validation methods
Cons of Yup
- Larger bundle size, which may impact performance in larger applications
- Less flexible for complex, nested object validations
- Steeper learning curve for advanced use cases
Code Comparison
Yup:
const schema = yup.object().shape({
name: yup.string().required(),
age: yup.number().positive().integer().required(),
});
schema.validate({ name: 'John', age: 30 })
.then(valid => console.log(valid))
.catch(error => console.log(error));
Vest:
const suite = vest.create('user_form', (data = {}) => {
test('name', 'Name is required', () => {
enforce(data.name).isNotEmpty();
});
test('age', 'Age must be a positive integer', () => {
enforce(data.age).isNumber().positive().integer();
});
});
const result = suite({ name: 'John', age: 30 });
console.log(result.hasErrors());
Both libraries offer robust validation capabilities, but Yup provides a more declarative approach with its schema definition, while Vest offers a more imperative style with individual test functions. Vest's approach may be more flexible for complex scenarios, while Yup's schema-based validation can be more concise for simpler use cases.
TypeScript-first schema validation with static type inference
Pros of Zod
- More comprehensive type inference and static type checking
- Broader ecosystem with plugins and integrations
- Better support for complex object schemas and nested structures
Cons of Zod
- Larger bundle size and potentially slower performance
- Steeper learning curve for complex use cases
- Less focus on form validation specific features
Code Comparison
Zod schema definition:
const UserSchema = z.object({
username: z.string().min(3).max(20),
email: z.string().email(),
age: z.number().min(18).optional(),
});
Vest validation suite:
suite('user', (data) => {
test('username', 'Username is required', () => {
enforce(data.username).isNotEmpty().longerThan(2).shorterThan(21);
});
test('email', 'Invalid email', () => {
enforce(data.email).isEmail();
});
test('age', 'Must be 18 or older', () => {
enforce(data.age).optional().greaterThanOrEquals(18);
});
});
Both libraries offer schema validation, but Zod focuses on TypeScript integration and type inference, while Vest provides a more declarative approach tailored for form validation scenarios.
The most powerful data validation library for JS
Pros of Joi
- More mature and widely adopted, with a larger ecosystem and community support
- Offers a broader range of validation features and data types
- Provides built-in coercion and type conversion capabilities
Cons of Joi
- Heavier and more complex, potentially impacting performance for simpler use cases
- Steeper learning curve due to its extensive API and configuration options
- Less focused on client-side validation compared to Vest
Code Comparison
Joi:
const schema = Joi.object({
username: Joi.string().alphanum().min(3).max(30).required(),
email: Joi.string().email().required()
});
const { error, value } = schema.validate({ username: 'john_doe', email: 'john@example.com' });
Vest:
import { create, test, enforce } from 'vest';
const suite = create((data = {}) => {
test('username', 'Username is required', () => {
enforce(data.username).isNotEmpty().longerThan(2).shorterThan(31);
});
test('email', 'Email is invalid', () => {
enforce(data.email).isNotEmpty().isEmail();
});
});
const result = suite({ username: 'john_doe', email: 'john@example.com' });
Both libraries offer robust validation capabilities, but Joi focuses on server-side validation with a more extensive feature set, while Vest is designed for both client and server-side validation with a simpler API and better performance for smaller applications.
Decorator-based property validation for classes.
Pros of class-validator
- Integrates seamlessly with TypeScript and decorators, providing type-safe validation
- Offers a wide range of built-in validation decorators for common use cases
- Supports custom validation functions and asynchronous validation
Cons of class-validator
- Requires the use of classes and decorators, which may not fit all project structures
- Can be more verbose for simple validation scenarios
- Limited flexibility in defining custom validation rules compared to Vest
Code Comparison
class-validator:
import { IsString, MinLength, IsEmail } from 'class-validator';
class User {
@IsString()
@MinLength(2)
name: string;
@IsEmail()
email: string;
}
Vest:
import { create, test, enforce } from 'vest';
const suite = create((data = {}) => {
test('name', 'Name is required', () => {
enforce(data.name).isNotEmpty().longerThan(1);
});
test('email', 'Email must be valid', () => {
enforce(data.email).isEmail();
});
});
Both libraries offer robust validation capabilities, but class-validator is more tightly coupled with TypeScript and object-oriented programming paradigms, while Vest provides a more flexible, function-based approach to validation that can be easily integrated into various project structures.
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Pros of Ajv
- Highly performant JSON schema validator with extensive support for JSON Schema standards
- Supports custom keywords and formats for advanced validation scenarios
- Large ecosystem with plugins and integrations for various frameworks
Cons of Ajv
- Steeper learning curve due to its comprehensive feature set
- Primarily focused on JSON schema validation, which may be overkill for simpler use cases
- Configuration can be more complex for basic validation needs
Code Comparison
Ajv:
const Ajv = require("ajv")
const ajv = new Ajv()
const schema = {
type: "object",
properties: {
foo: { type: "integer" },
bar: { type: "string" }
},
required: ["foo"],
additionalProperties: false
}
const validate = ajv.compile(schema)
Vest:
import { create, test, enforce } from 'vest';
const suite = create((data = {}) => {
test('foo', 'Foo is required', () => {
enforce(data.foo).isNotEmpty();
});
test('bar', 'Bar must be a string', () => {
enforce(data.bar).isString();
});
});
The code comparison shows that Ajv uses a JSON schema approach for defining validation rules, while Vest employs a more programmatic and declarative style. Ajv's schema is more concise for complex structures, but Vest's approach may be more intuitive for developers familiar with unit testing patterns.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Vest - Declarative validations framework

Vest is a validation framework that looks and feels like a unit testing framework. It is designed to be easy to learn, highly maintainable, and framework-agnostic.
Write your validations as if they were unit tests, and run them in your app.
import { create, test, enforce } from 'vest';
const suite = create(data => {
test('username', 'Username is required', () => {
enforce(data.username).isNotBlank();
});
test('username', 'Username must be at least 3 chars', () => {
enforce(data.username).longerThanOrEquals(3);
});
test('username', 'Username already taken', async () => {
await doesUserExist(data.username);
});
});
const result = await suite.run(formData);
Why Vest?
Writing form validations can be messy. Vest cleans it up by separating validation logic from feature logic and providing a familiar, powerful syntax.
ð¡ Easy to Learn
Vest adopts the syntax and style of unit testing frameworks (Mocha, Jest). If you've written a test, you already know Vest.
ð¨ Framework Agnostic
React, Vue, Svelte, Angular, or Vanilla JS - Vest works everywhere. It doesn't depend on your UI library.
ð¡ï¸ Type Safe
Vest is written in TypeScript and provides first-class type support, including typed suites and results.
ð Standard Schema Support
Vest implements the Standard Schema spec, making it a drop-in replacement for Zod or Yup in libraries like React Hook Form.
â¡ SSR & Hydration
Built-in support for server-side validation and state hydration (runStatic, SuiteSerializer), enabling seamless full-stack validation flows.
ð§© Extendable & Composable
Create custom rules, compose existing ones, or use the optional schema validation (n4s) to enforce data structure.
Installation
npm i vest
Getting Started
Check out the Vest Documentation for guides, API references, and examples.
Playgrounds
Contribute
We welcome contributions! See CONTRIBUTING.md for details.
Top Related Projects
String validation
Dead simple Object schema validation
TypeScript-first schema validation with static type inference
The most powerful data validation library for JS
Decorator-based property validation for classes.
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot