egg-validate-ext

1.0.4 • Public • Published

egg-validate

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

Validate plugin for egg.

see parameter for more information such as custom rule.

Install

$ npm i egg-validate --save

Usage

// {app_root}/config/plugin.js
exports.validate = {
  package: 'egg-validate',
};

Validate Request Body

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

Extend Rules

  • app.js
app.validator.addRule('jsonString', (rule, value) => {
  try {
    JSON.parse(value);
  } catch (err) {
    return 'must be json string';
  }
});

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-validate-ext

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

473 kB

Total Files

25

Last publish

Collaborators

  • hyb76788424