Skip to content

Commit

Permalink
nect release with new rules and change logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bitnbytesio committed Jun 11, 2019
1 parent d917ce3 commit c16b0dd
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 2 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- nothing
- gt: greater then another field rle
- gte: greater then or equals another field rle
- lt: less then another field rle
- lte: less then or equals another field rle

### Changed

Expand All @@ -25,6 +28,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- nothing

### Security

- nothing

## [3.3.0]

### Fixed

- between rule
- lengthBetween rule

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-input-validator",
"version": "3.3.0",
"version": "3.4.0-rc1",
"description": "validation library for nodejs, inspired by laravel.",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/messages/en/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module.exports = {
domain: 'The :attribute must be a valid domain.',
email: 'The :attribute must be a valid email address.',
equals: 'The :attribute must be a equals :arg0.',
gt: 'The :attribute must be greater then :args',
gte: 'The :attribute must be greater then or equals to :args',
lt: 'The :attribute must be less then :args',
lte: 'The :attribute must be less then or equals :args',
hash: 'The :attribute must be a valid :arg0 hash.',
hex: 'The :attribute must be a valid hex.',
hexColor: 'The :attribute must be a valid hex color.',
Expand Down
19 changes: 19 additions & 0 deletions src/rules/gt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const empty = require('../lib/empty');
const { pathIndex } = require('../lib/ObjectIndex');
const numeric = require('./numeric');

module.exports = async function gt(field, value, anotherField) {


const anotherFieldValue = pathIndex(this.inputs, anotherField);

if (!(await numeric(field, anotherFieldValue))) {
return false;
}

if (Number(value) > Number(anotherFieldValue)) {
return true;
}

return false;
}
19 changes: 19 additions & 0 deletions src/rules/gte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const empty = require('../lib/empty');
const { pathIndex } = require('../lib/ObjectIndex');
const numeric = require('./numeric');

module.exports = async function gte(field, value, anotherField) {


const anotherFieldValue = pathIndex(this.inputs, anotherField);

if (!(await numeric(field, anotherFieldValue))) {
return false;
}

if (Number(value) >= Number(anotherFieldValue)) {
return true;
}

return false;
}
4 changes: 4 additions & 0 deletions src/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ exports.digitsBetween = require('./digitsBetween');
exports.domain = require('./domain');
exports.email = require('./email');
exports.equals = require('./equals');
exports.gt = require('./gt');
exports.gte = require('./gte');
exports.lt = require('./lt');
exports.lte = require('./lte');
exports.hash = require('./hash');
exports.hex = require('./hex');
exports.hexColor = require('./hexColor');
Expand Down
19 changes: 19 additions & 0 deletions src/rules/lt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const empty = require('../lib/empty');
const { pathIndex } = require('../lib/ObjectIndex');
const numeric = require('./numeric');

module.exports = async function lt(field, value, anotherField) {


const anotherFieldValue = pathIndex(this.inputs, anotherField);

if (!(await numeric(field, anotherFieldValue))) {
return false;
}

if (Number(value) < Number(anotherFieldValue)) {
return true;
}

return false;
}
19 changes: 19 additions & 0 deletions src/rules/lte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const empty = require('../lib/empty');
const { pathIndex } = require('../lib/ObjectIndex');
const numeric = require('./numeric');

module.exports = async function gte(field, value, anotherField) {


const anotherFieldValue = pathIndex(this.inputs, anotherField);

if (!(await numeric(field, anotherFieldValue))) {
return false;
}

if (Number(value) <= Number(anotherFieldValue)) {
return true;
}

return false;
}
18 changes: 18 additions & 0 deletions test/multiLevelAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ describe('Array Fields', function () {

});

it('rule accepting another fileds as seed', async () => {

let v = new Validator(
{
range: {min : 2, max: 5}
},
{
'range.min': 'required|integer',
'range.max': 'required|integer|gt:range.min',
});

let matched = await v.check();


assert.equal(matched, true);

});

it('should pass', async () => {

let v = new Validator(
Expand Down
44 changes: 44 additions & 0 deletions test/rules/gt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const assert = require('assert');

const Validator = require('../../index');


let r = {};


describe('gt', function () {

it('validation should pass', async () => {

const v = new Validator(
{ min: '20', max: '25' },
{
min: 'required|integer',
max: 'required|integer|gt:min'
}
);

const matched = await v.check();

assert.equal(matched, true);

});

it('validation should fail', async () => {

const v = new Validator(
{ min: '30', max: '25' },
{
min: 'required|integer',
max: 'required|integer|gt:min'
}
);

const matched = await v.check();

assert.equal(matched, false);

});


});
60 changes: 60 additions & 0 deletions test/rules/gte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const assert = require('assert');

const Validator = require('../../index');


let r = {};


describe('gte', function () {

it('validation should pass with greater seed', async () => {

const v = new Validator(
{ min: '20', max: '25' },
{
min: 'required|integer',
max: 'required|integer|gte:min'
}
);

const matched = await v.check();

assert.equal(matched, true);

});

it('validation should pass with equal', async () => {

const v = new Validator(
{ min: '20', max: '20' },
{
min: 'required|integer',
max: 'required|integer|gte:min'
}
);

const matched = await v.check();

assert.equal(matched, true);

});

it('validation should fail', async () => {

const v = new Validator(
{ min: '30', max: '25' },
{
min: 'required|integer',
max: 'required|integer|gte:min'
}
);

const matched = await v.check();

assert.equal(matched, false);

});


});
44 changes: 44 additions & 0 deletions test/rules/lt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const assert = require('assert');

const Validator = require('../../index');


let r = {};


describe('lt', function () {

it('validation should pass', async () => {

const v = new Validator(
{ min: '20', max: '25' },
{
min: 'required|integer|lt:max',
max: 'required|integer'
}
);

const matched = await v.check();

assert.equal(matched, true);

});

it('validation should fail', async () => {

const v = new Validator(
{ min: '30', max: '25' },
{
min: 'required|integer|lt:max',
max: 'required|integer'
}
);

const matched = await v.check();

assert.equal(matched, false);

});


});
60 changes: 60 additions & 0 deletions test/rules/lte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const assert = require('assert');

const Validator = require('../../index');


let r = {};


describe('lte', function () {

it('validation should pass with greater seed', async () => {

const v = new Validator(
{ min: '20', max: '25' },
{
min: 'required|integer|lte:max',
max: 'required|integer'
}
);

const matched = await v.check();

assert.equal(matched, true);

});

it('validation should pass with equal', async () => {

const v = new Validator(
{ min: '20', max: '20' },
{
min: 'required|integer|lte:max',
max: 'required|integer'
}
);

const matched = await v.check();

assert.equal(matched, true);

});

it('validation should fail', async () => {

const v = new Validator(
{ min: '30', max: '25' },
{
min: 'required|integer|lte:max',
max: 'required|integer'
}
);

const matched = await v.check();

assert.equal(matched, false);

});


});

0 comments on commit c16b0dd

Please sign in to comment.