/egg-property-validator

egg plugin for property-validator

Primary LanguageJavaScriptMIT LicenseMIT

egg-property-validator

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

see property-validator.

Install

$ npm i egg-property-validator --save

Usage

// {app_root}/config/plugin.js
exports.propertyValidator = {
  enable: true,
  package: 'egg-property-validator',
};

Configuration

// {app_root}/config/config.default.js
exports.propertyValidator = {
  isTheUltimateAnswer(propertyName) {
  // and then return a function that takes the
  // actual object you want to validate
    return function(subject) {
      const value = subject[propertyName];
      const isAnswer = value === 42;
      // Make sure your function returns `result`, `message`
      // and `field`
      return {
        result: isAnswer,
        message: value + ' is not the Answer to the Ultimate Question of Life, The Universe, and Everything',
        field: propertyName,
      };
    };
  },
};

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

Example

see app/extend/validation.js

Questions & Suggestions

Please open an issue here.

License

MIT