egg-validate
validate plugin for egg
Last updated 7 years ago by fengmk2 .
MIT · Repository · Bugs · Original npm
$ cnpm install egg-validate 
SYNC missed versions from official npm registry.

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

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

Configurations

egg-validate support all parameter's configurations, check parameter documents to get more infomations.

// config/config.default.js
exports.validate = {
  // convert: false,
  // validateRoot: false,
};

Validate Request Body

// app/controller/home.js
exports.index = function* () {
  this.validate({ id: 'id' }); // will throw if invalid
  // or
  const errors = this.app.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

Current Tags

  • 2.0.2                                ...           latest (7 years ago)
  • 1.1.2                                ...           latest-1 (4 years ago)

3 Versions

  • 1.1.2                                ...           4 years ago
  • 2.0.2                                ...           7 years ago
  • 1.1.1                                ...           7 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org