项目作者: eggjs

项目描述 :
async validate plugin base on async-validator
高级语言: JavaScript
项目地址: git://github.com/eggjs/egg-async-validator.git
创建时间: 2017-03-06T16:09:50Z
项目社区:https://github.com/eggjs/egg-async-validator

开源协议:MIT License

下载


egg-async-validator

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

Async validate plugin for egg.

See async-validator for more information such as custom rule.

Install

  1. $ npm i egg-async-validator --save

Enable plugin

  1. // config/plugin.js
  2. exports.validate = {
  3. enable: true,
  4. package: 'egg-async-validator',
  5. };

Validate rules

All validate rules store on app/xxxx

Validate Request Body

  1. // app/controller/home.js
  2. exports.index = async () => {
  3. await this.validate({ id: 'id' }); // will throw if invalid
  4. // or
  5. const errors = await this.validator.validate({ id: 'id' }, this.request.body);
  6. };

Extend Rules

TBD

Questions & Suggestions

Please open an issue here.

License

MIT