ov
v0.1.1
Published
object validation made easy
Downloads
6
Readme
ov
ov is a object validation library which can be used in the browser or with nodejs
Installation
$ npm install --save ov
Usage
NodeJS
import { ov, Model, Blueprint } from 'ov';
const a = {
name: 'Sean_',
age: 19,
};
const b = new Blueprint({
name: new Model()
.string()
.max(25)
.alphanumeric(),
age: new Model()
.number()
.integer()
.min(16),
});
console.log('Valid', ov.validate(a, b));
Output
Valid Result {
valid: false,
errors:
[ ValidationError {
message: '\'name\' can only contain a-z, A-Z and 0-9',
path: 'name',
value: 'Sean_',
model: [StringModel],
check: [Check] } ] }
Browser
index.html
<script src="./dist/ov.js"></script>
script.js
const { ov, Model, Blueprint } = OV;
const a = {
name: 'Sean_',
age: 19,
};
const b = new Blueprint({
name: new Model()
.string()
.max(25)
.alphanumeric(),
age: new Model()
.number()
.integer()
.min(16),
});
console.log('Valid', ov.validate(a, b));
Output
Valid Result {
valid: false,
errors:
[ ValidationError {
message: '\'name\' can only contain a-z, A-Z and 0-9',
path: 'name',
value: 'Sean_',
model: [StringModel],
check: [Check] } ] }