You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

egg-validate

Package Overview
Dependencies
1
Maintainers
5
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-validate

validate plugin for egg


Version published
Weekly downloads
6.5K
increased by2.48%
Maintainers
5
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Package last updated on 17 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc