0.1.0 • Published 8 years ago

isomorphic-validation v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

ISOMORPHIC VALIDATION Build Status

An isomorphic validation engine for browser client and node app.

Engine - the core engine inside the validation

Node.js

npm install --save isomorphic-validation
import isomorphicValidation from isomorphicValidation;

const iv = new isomorphicValidation();

// implement
iv.addValidation({
  'required': {
    'validator': /^.+$/
  }
});

iv.validate({
  name: 'name',
  value: 'huei90',
  type: 'required'
})
.then((val) => console.log('form is valid'))
.catch((val) => console.log('form is invalid'));

Browser Client

Babel

Usage

Constructor

given parameter types

const iv = new isomorphicValidation(types)

Adding validation type

validator type accepts RegExp and Function

// adding multiples:
// iv.addValidation({'required': {validator: /^.+$/}, age: {validator: /\d+/}})

// adding function:
// iv.addValidation({'required': {validator: (v) => !!v})

validate form

validate the form(s) and return Promise

// validate form
iv.validate([{
    name: 'name',
    value: 'huei',
    type: 'required'
  },{
    name: 'age',
    value: 30,
    type: 'age']
  }])
  .then(/* ... */)
  .catch(/* ... */);

return all types

iv.getAllTypes(); // => all types

License

MIT

0.1.0

8 years ago