Skip to content

Commit

Permalink
Merge pull request #5 from swaibat/ch-add-badges
Browse files Browse the repository at this point in the history
chore(rect-empty):rectify not null constrains and edit readme file
  • Loading branch information
swaibat committed Sep 22, 2019
2 parents 85430a1 + 83a294d commit 002ed7d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 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`|
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eagle-validator",
"version": "1.0.0",
"version": "1.0.1",
"description": "A modern javascript object validation NPM package available on npmjs.com",
"main": "index.js",
"nyc": {
Expand Down
6 changes: 2 additions & 4 deletions package/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-disable no-useless-escape */
/* eslint-disable prefer-destructuring */
/* eslint-disable no-prototype-builtins */

class Validate {
constructor(data) {
this.key = Object.entries(data)[0][0];
this.val = Object.entries(data)[0][1].body[this.key];
this.error = '';
this.error = undefined;
this.status = 200;
this.data = Object.entries(data)[0][1].body;
}
Expand Down

0 comments on commit 002ed7d

Please sign in to comment.