0.1.1 • Published 5 years ago

ov v0.1.1

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

ov logo

ov

ov is a object validation library which can be used in the browser or with nodejs

npm version license

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] } ] }