7.2.0 • Published 7 years ago
ms-validation v7.2.0
Validation module
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.
Installation
npm i ms-validation -S
Usage
// Lets assume that we have a following file structure:
//
// .
// ./schemas/config.json
// ./schemas/ping.json
// ./index.js
//
const Errors = require('common-errors');
const Validator = require('ms-amqp-validation');
const validator = new Validator('./schemas');
// some logic here
validator.validate('config', {
configuration: 'string'
})
.then(doc => {
// all good
// handle doc, which would eq { configuration: 'string' }
})
.catch(Errors.ValidationError, (error) => {
// handle error here
});
const result = validator.validateSync('config', { data: true });
if (result.error) {
// handle error!
}
// do stuff
// ...
// init filter
validator.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 errors
validator.filter('config', { conf: 'string', extra: true })
.then(result => {
// { conf: 'string' }
});
7.2.0
7 years ago
7.1.0
7 years ago
7.0.0
7 years ago
6.0.2
8 years ago
6.0.1
8 years ago
6.0.0
8 years ago
5.0.1
8 years ago
5.0.0
8 years ago
4.0.0
8 years ago
3.0.0
9 years ago
2.0.0
9 years ago
1.1.1
9 years ago
1.1.0
9 years ago
1.0.1
10 years ago
1.0.0
10 years ago
0.5.7
10 years ago
0.5.6
10 years ago
0.5.5
10 years ago
0.5.4
10 years ago
0.5.3
10 years ago
0.5.1
10 years ago
0.5.0
10 years ago