1.0.0 • Published 7 years ago

egg-async-validator-best v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

https://github.com/yiminghe/async-validator

egg-async-validator-best

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-async-validator-best --save

Usage

// {app_root}/config/plugin.js
exports.asyncValidatorBest = {
  enable: true,
  package: 'egg-async-validator-best',
};

Configuration

// {app_root}/config/config.default.js
exports.asyncValidatorBest = {
};

see config/config.default.js for more detail.

Example

  • 基于async-validator 的egg验证插件
    //post 验证
    const rule = {
	lng: { type: 'string', required: true, message: '必填项' },
	lat: { type: 'string', required: true }
    }
    await this.ctx.validate(rule)  //默认校验 this.ctx.request.body
    //or
    //get
    await this.ctx.validate(rule,this.ctx.query)
    //自定义
    await this.ctx.validate(rule,{
        lng:'11',
        lat:""
    })

Questions & Suggestions

Please open an issue here.

License

MIT