egg-property-validator
see property-validator.
Install
$ npm i egg-property-validator --save
Usage
// {app_root}/config/plugin.js
exports.propertyValidator = {
enable: true,
package: 'egg-property-validator',
};
Configuration
// {app_root}/config/config.default.js
exports.propertyValidator = {
isTheUltimateAnswer(propertyName) {
// and then return a function that takes the
// actual object you want to validate
return function(subject) {
const value = subject[propertyName];
const isAnswer = value === 42;
// Make sure your function returns `result`, `message`
// and `field`
return {
result: isAnswer,
message: value + ' is not the Answer to the Ultimate Question of Life, The Universe, and Everything',
field: propertyName,
};
};
},
};
see config/config.default.js for more detail.
Example
Questions & Suggestions
Please open an issue here.