@alifd/validate

1.4.0 • Public • Published

Validate

Validation to be used with @alifd/field Install with npm install @alifd/validate

Basic Usage

Callback

const rules = {
  myInput: function (rule, value, cb, options) {
    if (value <= 100) {
      cb('Value must be more than 100');
    } else {
      cb();
    }
  }
}
const validator = new Validator(rules);
validator.validate({ myInput: 90 }, (err) => { console.log(err)});

Promise

const rules = {
  myInput: function (rule, value, cb, options) {
    if (value <= 100) {
      cb('Value must be more than 100');
    } else {
      cb();
    }
  }
}
const validator = new Validator(rules);
validator.validatePromise({ myInput: 90 })
  .then((err) => { console.log(err)})

API

Initialization

let validator = new Validator(rules [, options]);
Parameter Description Type Optional Default
rules Map of rule names to validation functions { [ruleName] : Array of validation functions } yes undefined
options validation options Object yes {}

options configuration item

Parameters Description Type Default
first should only return the first error found amongst rules Boolean undefined
messages map to override default messages Object (see ./src/messages)

Development

Testing

npm run test - triggers a one-time full run of all unit tests npm run test-watch - triggers a run of all unit tests, but watches for any changes to code or tests and reruns all tests.

Making commits

Commits must be in the following format TYPE(SCOPE): MESSAGE, where SCOPE is optional. e.g. fix: validatePromise return value Review the commitlint.config.js file to see allowed types.

Release

There are 2 main branches: Master and Develop. Master holds the latest code that is contained in the npm package. Develop is the development branch used for queueing package changes and any final validation. All development should occur on another branch and then be merged into Develop.

Travis CI will run tests on each pull request and push. If the push is to master then an additional release step runs. The release step uses semantic-release to determine the correct version, tag the master branch, and release the new package to npm.

NOTE: the package.json file needs to be updated manually after the release.

Readme

Keywords

Package Sidebar

Install

npm i @alifd/validate

Weekly Downloads

3,058

Version

1.4.0

License

MIT

Unpacked Size

98.1 kB

Total Files

19

Last publish

Collaborators

  • soberz
  • whatever_lll
  • john-watson
  • eternalsky
  • mark-ck
  • lakerswgq
  • no-repeat
  • wwsun
  • aboutblank
  • bindoon
  • tao1991123
  • vicerwang
  • myronliu347
  • jdkahn
  • fusion-bot
  • sobear
  • lianmin
  • clarkxia
  • quanyin
  • jerryyxu
  • yellow2dong
  • alvinhui
  • andevery
  • luhengchang228
  • yuysmile
  • fd.xy
  • rax-publisher