Simple library for checking schema types by another schema with reference.
npm i schema-type-validation -s
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);
// [ ]
✓ 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.