egg-joi-new
- 改进自egg-joi, 使用最新版的@hapi/joi ,并且添加了中文提示支持~
- Improved from egg-joi, using the latest version of @ hapi / joi, and added Chinese hint support
Install
$ npm i egg-joi-new --save
Usage
// {app_root}/config/plugin.jsexportsjoi = enable: true package: 'egg-joi-new';
Configuration
// {app_root}/config/config.default.jsexportsjoi = options: {} locale: 'zh-cn': true // if you don't need error message with chinese ,you can set to false throw: true // throw error when capture exception { // when throw is true the error message format return error; } { // when throw is false the error message format return error; } { // fromat result return result; };
Example
app/validator/sessions
'use strict'; module { const Joi = appJoi; return login: Joiobject };
app/controller/sessions
'use strict'; module { Controller async { thisctx; // if get error, ctx.body will be return thisbody = 'hello'; } return SessionsController; };