From 3b4d55e01e63881e59a1f4050ad46a5b581cbe20 Mon Sep 17 00:00:00 2001 From: Swaibu Rumbiiha Date: Sun, 22 Sep 2019 11:44:34 +0200 Subject: [PATCH 1/3] chore(rect-empty):rectiful not null constatrains --- package/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package/index.js b/package/index.js index 507b561..6eec97f 100644 --- a/package/index.js +++ b/package/index.js @@ -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; } From 9cbd5fc4c3aaa31a154fe53b307975aabb087f95 Mon Sep 17 00:00:00 2001 From: Swaibu Rumbiiha Date: Sun, 22 Sep 2019 11:49:33 +0200 Subject: [PATCH 2/3] 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4b9d25..978d005 100644 --- a/package.json +++ b/package.json @@ -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": { From 83a294d7f5b389f60357977b53953fdebb0143b4 Mon Sep 17 00:00:00 2001 From: Swaibu Rumbiiha Date: Sun, 22 Sep 2019 12:27:45 +0200 Subject: [PATCH 3/3] choreedit-readme):add content inthe readme file --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index c35e89a..0b8030f 100644 --- a/README.md +++ b/README.md @@ -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`| \ No newline at end of file