validator-schema

Validate objects based on schema.

Usage no npm install needed!

<script type="module">
  import validatorSchema from 'https://cdn.skypack.dev/validator-schema';
</script>

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.