eggjs / egg-async-validator

async validate plugin base on async-validator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

$ npm i egg-async-validator --save

Enable plugin

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

Validate rules

All validate rules store on app/xxxx

Validate Request Body

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

Extend Rules

TBD

Questions & Suggestions

Please open an issue here.

License

MIT

About

async validate plugin base on async-validator

License:MIT License


Languages

Language:JavaScript 100.0%