Skip to content

Commit

Permalink
choreedit-readme):add content inthe readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
swaibat committed Sep 22, 2019
1 parent 9cbd5fc commit 83a294d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,46 @@
[![Coverage Status](https://coveralls.io/repos/github/swaibat/eagle-validator/badge.svg?branch=master)](https://coveralls.io/github/swaibat/eagle-validator?branch=master)

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 sendResult(res, 400, 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`|

0 comments on commit 83a294d

Please sign in to comment.