Skip to content

Simple library for checking schema types by another schema with reference.

License

Notifications You must be signed in to change notification settings

jonathan-sh/schema-type-validation

Repository files navigation

CircleCI Build Status npm version

schema-type-validation

Simple library for checking schema types by another schema with reference.

install

npm i schema-type-validation -s

using

const { compare } = require('schema-type-validation');

//object to reference
const reference = { a: '', b: 0, c: true, d : { e: [ 0 ] } };

//setting wrong schema
let to_check = { a:  0, b:'', c: 'oi'};

//getting the errors
let errors = compare(reference, to_check);
console.log(errors);
// [ 
//   { path: 'a', required: 'string', informed: 'number' },
//   { path: 'b', required: 'number', informed: 'string' },
//   { path: 'c', required: 'boolean', informed: 'string' },
//   { path: 'd.e', required: 'number[]', informed: 'undefined' } 
// ]

//setting right schema
to_check = { a: 'name', b: 42, c: false, d : { e: [ -1 ] } };

//getting the errors
errors = compare(reference, to_check);
console.log(errors);
// [ ]

you can check:

✓ string or string[]
✓ number or number[]
✓ boolean or boolean[]
✓ object or object[]
✓ multiple errors
✓ sublevels validation

Remember, this library is to help verify types, not values.

About

Simple library for checking schema types by another schema with reference.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published