Socket
Book a DemoInstallSign in
Socket

egg-async-ivalidator

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-async-ivalidator

the async validator plugin for egg, compatible egg-validate method

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

egg-async-ivalidator

Validate plugin for egg, compatible egg-validate method.

see async-validate for more information such as custom rule.

Install

$ npm i egg-async-ivalidator --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.validate = {
  messages: {},
};

see async-validator#messages for more detail.

Example

// {app_root}/app/controller/home.js
exports.index = async ctx => {

  // will throw if invalid.
  await ctx.validate({
    data: { type: 'object', required: true },
  }, {
    data: '1',
  });

  // if you want to get errors info,
  // use try { ... } catch (err) { ... } to get
  // example
  try {
    await ctx.validate({ data: { type: 'object', required: true } }); // validate target, default to `this.request.body`
  } catch (err) {
    const errors = err.errors;
  }

};

rules see async-validator#rules for more detail.

!!important: method,date,hex in type does not apply to server - side form validation

Keywords

egg

FAQs

Package last updated on 24 Jun 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.