0.0.22-alpha • Published 5 years ago
egg-async-avalidator v0.0.22-alpha
egg-async-avalidator
Async validate plugin for egg
See async-validator for more information such as custom rule.
The 'message' is not only a 'string', it can be 'any'.
Install
$ npm i egg-async-avalidator --save
Usage
// {app_root}/config/plugin.js
exports.asyncAvalidator = {
enable: true,
package: 'egg-async-avalidator',
};
Configuration
// {app_root}/config/config.default.js
exports.asyncAvalidator = {
};
see config/config.default.js for more detail.
Example
const rules = {
name: {required: true, message: 'name can not be empty'}
}
try {
await app.avalidator(rules).validate({name: ''})
} catch(err) {
// do someting
}
or
const rules = {
name: {required: true, message: 'name can not be empty'}
}
try {
await ctx.avalidate(rules, {name: ''})
} catch(err) {
// do someting
}
License
0.0.22-alpha
5 years ago
0.0.21-alpha
5 years ago
0.0.2-alpha
5 years ago
0.0.1-alpha
5 years ago
1.0.0
5 years ago