validator-schema
v0.1.2
Published
Validate objects based on schema.
Downloads
5
Readme
validator-schema
Install (already includes TypeScript definition file).
npm i -S validator-schema
Schema validation example
import validator, { Schema } from 'validator-schema';
const schema: Schema = {
name: {
type: 'string',
test: /goku/i,
fn: v => v && v.length > 0,
},
};
const validate = validator(schema);
const user = {
name: 'Goku',
};
validate(user); // { valid: true, errors: [] }
See tests for more examples.