0.0.22-alpha • Published 5 years ago

egg-async-avalidator v0.0.22-alpha

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

egg-async-avalidator

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

Async validate plugin for egg

See async-validator for more information such as custom rule.

The 'message' is not only a 'string', it can be 'any'.

Install

$ npm i egg-async-avalidator --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.asyncAvalidator = {
};

see config/config.default.js for more detail.

Example

const rules = {
  name: {required: true, message: 'name can not be empty'}
}
try {
  await app.avalidator(rules).validate({name: ''})
} catch(err) {
  // do someting
}

or

const rules = {
  name: {required: true, message: 'name can not be empty'}
}

try {
  await ctx.avalidate(rules, {name: ''})
} catch(err) {
  // do someting
}

License

MIT