2.0.2 • Published 3 years ago

egg-validate v2.0.2

Weekly downloads
5,976
License
MIT
Repository
github
Last release
3 years ago

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',
};

Validate Request Body

// 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

1.1.2

3 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago