eagle-validator
A modern javascript object validation NPM package available on npmjs.com
Last updated 8 months ago by swaibu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install eagle-validator 
SYNC missed versions from official npm registry.

eagle-validator

Build Status Coverage Status

A modern javascript object validation node package available on npmjs.com

Basic usage

a simple middleware for you

import Check from 'eagle-validator';

export default function validator(req, res, next) {
  const valid = [
    new Check({ firstName: req }).str().req().min(2).max(20).alpha(),
    new Check({ phoneNumber: req }).str().req().min(2).num(),
    new Check({ email: req }).str().req().email(),
  ];
  const invalid = valid.find((e) => e.error);
  if (invalid) return res.status(400).send({ status:400, message:invalid.error });
  return next();
}

this will return simplified messages like:

for required field

firstName field is required

firstName should be a string

firstName should be greaterthan 2

firstName should be lessthan 19

firstName should be alphabetic

Basic abbrevations used

abbrevations meaning example
str() string 'hello'
req() required 'world'
min() minimum characters any
max(3) miximum characters any
number() should be a number 1-9
num() only numbers in a string 0-9
alpha() should ba alphabets only A-Z,a-z
alphaNum() mixture of alpha & nums A-Z,a-z,0-9
bool() should be a boolean true
email() stictly email address rswaib@gmail.com

Current Tags

  • 1.0.8                                ...           latest (8 months ago)

9 Versions

  • 1.0.8                                ...           8 months ago
  • 1.0.7                                ...           8 months ago
  • 1.0.6                                ...           8 months ago
  • 1.0.5                                ...           8 months ago
  • 1.0.4                                ...           8 months ago
  • 1.0.3                                ...           8 months ago
  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |