data-validators
Validators that help make sure your data follow specific constraints.
Last updated 2 years ago by cbutcher .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install data-validators 
SYNC missed versions from official npm registry.

Data Validators

Build Status Contributions Welcome

Installation

> npm install --save data-validators 

Using the Validator Service

We have a validation service that helps to manage and execute the wide range of validators that we have. You can get the service by requiring it from our module...

const { Validator } = require('data-validators');

With the Validator service we can check() the value below to make sure that it meets our range validator. Since the value 123 is outside of the 0 - 100 range, our validator will throw an error.

let errors = Validator.check(123, 'range', {
    min: 0,
    max: 100,
    message: 'Value must be in-between {min} and {max}'
});

console.log(errors); // outputs: ['Value must be in-between 0 and 100']

Executing a Validator Directly

You can also get and execute a single validator from our module...

const { Range } = require('data-validators');

let range = new Range({
    min: 0,
    max: 100,
    message: 'Range must be in-between {min} and {max}'
});

let errors = range.validate(250); // outputs: ['Range must be in-between 0 and 100']

Current Tags

  • 1.0.3                                ...           latest (2 years ago)

4 Versions

  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |