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
Parameter | Default | Description |
---|---|---|
schema | None | The 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 = const schema = type: 'object' properties: email: type: 'string' format: 'email' required: 'email' ; const model = {}; let validator = ; const valid = validator; // => false validatorerrors; // => { email: { required: 'should have required property email' } } validatorpaths; // => ['email.required'] validator = ; const valid = validator; validatorerrors; // => { 'email..required': 'should have required property email' } validatorpaths; // => ['email.required']