Coder Social home page Coder Social logo

eagle-validator's Introduction

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 [email protected]

eagle-validator's People

Contributors

swaibat avatar

Watchers

James Cloos avatar  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.