Skip to content

theonlyducks/validation.js

Repository files navigation

Validation.js

JavaScript validation engine

Version Project Size Dependencies Licence

Table of contents

Documentation

See

Getting started

Installation

yarn add @theonlyducks/valitaion.js

Usage

Basic usage

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);
	}
}

Advanced usage

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);
	}
}

Development

Install

yarn

Run tests

yarn test

License

MIT © The Only Ducks