2.0.0 • Published 5 years ago

jschemator v2.0.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
5 years ago

jschemator

Simple npm package to validate an object using JSON Schema, and get errors in friendly form, useful to validate on frontend and backend!

Install

$ npm install jschemator

Options

ParameterDefaultDescription
schemaNoneThe JSON schema to validate, this plugin uses ajv check the docs to create your schemas
locale'en'Locale to error messages, this plugin uses ajv-i18n, see the doc to all available languages
options{allErrors: true, flat: false}ajv options, this plugin uses ajv see the doc to all options

Usage

Simple

const jschemator = require('jschemator')

const schema = {
  type: 'object',
  properties: {
    email: {
      type: 'string',
      format: 'email'
    }
  },
  required: ['email']
 };
 
 const model = {};
 let validator = jschemator(schema, 'en');
 
 const valid = validator.validate(model);
 // => false
 
 validator.errors;
 // => { email: { required: 'should have required property email' } }
 validator.paths;
 // => ['email.required']

 validator = jschemator(schema, 'en', {flat: true});
 
 const valid = validator.validate(model);

 validator.errors;
 // => { 'email..required': 'should have required property email' }
 validator.paths;
 // => ['email.required']
 
2.0.0

5 years ago

1.0.0

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

7 years ago

0.2.5

7 years ago

0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago