object-validator is minimalistic (400b uncompressed), elegant and pluggable object validation library
object-validator supports modern browser. You'll need to use polyfill to make it work for older ones.
Install
$ npm install @amoutonbrady/object-validator
$ yarn @amoutonbrady/object-validator
Usage
import { createSchema, isString } from '@amoutonbrady/object-validator';
const schema = createSchema({
key1: [isString],
_key2: [isString],
});
const [errors, pass] = schema.validate({ key1: 'test', key2: 'test' });
console.log({ errors, pass });
const [errors, pass] = schema.validate({ key1: 'test' });
console.log({ errors, pass });
const [errors, pass] = schema.validate({ key2: 'test' });
console.log({ errors, pass });
const [errors, pass] = schema.validate({ key2: true });
console.log({ errors, pass });