$ npm i egg-cute-validator --save
// {app_root}/config/plugin.js
exports.validator = {
enable: true,
package: 'egg-cute-validator',
};
config.validator = {
client: {
locale: 'en-US',
dirs: {
types: '',
messages: '',
rules: '',
},
},
};
Usage:
// set messages, message format { key: value }
await this.app.validator.setMessage('zh-CN', message);
// set Locale
await this.app.validator.setLocale('zh-CN');
// validate function
await this.app.validator.validate('login.signIn', data);
// validate function, The 'default' field is set in the rule to allow the verification to fail, and the data value is changed to the default value.
await this.app.validator.parameter('login.signIn', data);
see config/config.default.js for more detail.
Please open an issue here.