This is basically a wrapper of ajv module.
What it does - is accepts a directory with schemas, reads it in an async or sync fashion based on your preference
and caches validators under it's name, minus it's extension (to be completely honest - it strips down .json only).
Based on the bluebird promises.
npm i @microfleet/validation
// Lets assume that we have a following file structure://// .// ./schemas/config.json// ./schemas/ping.json// ./index.js//importErrors= require('common-errors');importValidator,{HttpStatusError}from'@microfleet/validation';constvalidator=newValidator('./schemas');awaitvalidator.init()// some logic herevalidator.validate('config',{configuration: 'string'}).then(doc=>{// all good// handle doc, which would eq { configuration: 'string' }}).catch(HttpStatusError,(error)=>{// handle error here});constresult=validator.validateSync('config',{data: true});if(result.error){// handle error!}// do stuff// ...// init filtervalidator.init('./dir',null,true);// all schemas in this dir will filter out additional properties instead of throwing an error// catches when we only have 417 errorsvalidator.filter('config',{conf: 'string',extra: true}).then(result=>{// { conf: 'string' }});