Introduction
EncolaJS Validator is a powerful and flexible validation library designed for JavaScript applications running in both browser and Node.js environments. It provides a comprehensive solution for validating complex data structures with an excellent developer experience.
Key Features
- Rich Rule Set: Extensive collection of built-in validation rules for various data types
- Path-based Validation: Support for deeply nested objects and arrays using dot notation
- Conditional Validation: Rules that depend on other field values
- Extensible: Easy to add custom validation rules and error messages
Installation
shell
npm i @encolajs/validatorshell
yarn add @encolajs/validatorshell
pnpm add @encolajs/validatorBasic Usage
Here's a simple example of how to use EncolaJS Validator:
javascript
import { createValidator } from '@encolajs/validator'
const validator = createValidator({
name: 'string',
age: 'number',
email: 'email'
})
const data = {
name: 'John Doe',
age: 30,
email: '[email protected]'
}
const isValid = await validator.validate(data)
if (isValid) {
console.log('Validation passed!')
} else {
console.log('Validation failed:', validator.getErrors())
}