JavaScript validation engine
See
yarn add @theonlyducks/valitaion.js
import Validate, { AssertError } from "valitaion.js";
const name = 'John Doe'
const props = new Validate();
props.ofValue(name).isString().isEmail();
try {
props.assertOne();
console.log('valid');
} catch (error) {
if (error instanceof AssertError) {
console.error('errors', errors.data);
}
}
import Validate, { AssertError } from "valitaion.js";
const data = {
name: 'John Doe',
email: '[email protected]'
};
const validate = new Validate();
validate
.addKey('name').required().notEmpty().isString()
.addKey('email').required().notEmpty().isString().isEmail();
try {
validate.assert(data);
console.log('valid');
} catch (error) {
if (error instanceof AssertError) {
console.error('errors', errors.data);
}
}
Install
yarn
Run tests
yarn test