Skip to content

eggjs/egg-async-validator

Repository files navigation

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

Releases

No releases published

Packages

No packages published