1.1.6 • Published 7 months ago

egg-cute-validator v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

egg-cute-validator

Install

$ npm i egg-cute-validator --save

Usage

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

Configuration

config.validator = {
  client: {
    locale: 'en-US',
    dirs: {
      types: '',
      messages: '',
      rules: '',
    },
  },
};

Usage:

// set messages, message format { key: value }
await this.app.validator.setMessage('zh-CN', message);

// set Locale
await this.app.validator.setLocale('zh-CN');

// validate function
await this.app.validator.validate('login.signIn', data, this.ctx);
await this.ctx.validate('login.signIn', data);

// validate function, The 'default' field is set in the rule to allow the verification to fail, and the data value is changed to the default value.
await this.app.validator.parameter('login.signIn', data, this.ctx);
await this.ctx.parameter('login.signIn', data);

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

Example

Questions & Suggestions

Please open an issue here.

License

MIT

1.1.6

7 months ago

1.1.5

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago