Code Monkey home page Code Monkey logo

validate's Introduction

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.

validate's People

Contributors

bindoon avatar dependabot[bot] avatar jdkahn avatar jiyeking avatar youluna avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.