Skip to content

Commit

Permalink
v3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bitnbytesio committed Jul 2, 2019
1 parent 9b3e05d commit 47f6c18
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 7 deletions.
19 changes: 15 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- 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
- nothing

### Changed

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

- nothing

## [3.4.0]

### Added

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

### Fixed

- typings
- multiple underscore (_) replacement with space issue

## [3.3.0]

### Fixed
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ The field under validation must be formatted as an e-mail address.
**equals**
The field under validation must be equal to given value.

**gt:another_field**
<sub>Added in: v3.4</sub>
The field under validation must be greater then another field value. This rule is for Numbers comparision.

**gte:another_field**
<sub>Added in: v3.4</sub>
The field under validation must be greater or equals to another field value. This rule is for Numbers comparision.

**hash:algo**
The field under validation must be a valid hash as per provided seed.

Expand Down Expand Up @@ -587,6 +595,14 @@ The field under validation value length must be between provided values.
let v = new Validator({age:''}, {age:'required|between:17,30'});
```

**lt:another_field**
<sub>Added in: v3.4</sub>
The field under validation must be less then another field value. This rule is for Numbers comparision.

**lte:another_field**
<sub>Added in: v3.4</sub>
The field under validation must be less or equals to another field value. This rule is for Numbers comparision.

**macAddress**
The field under validation should be a valid Mac Address.

Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ declare namespace Validator {

function koa();

export { setLang, extend, messages, koa };
export { setLang, extend, messages, customMessages, koa };
}

export = Validator;
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.4.0-rc1",
"version": "3.4.0",
"description": "validation library for nodejs, inspired by laravel.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class Validator {
}
}

return message.replace('_', ' ');
return message.replace(/_/g, ' ');

}

Expand Down
67 changes: 67 additions & 0 deletions test/customMessages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const assert = require('assert');

const should = require('should');

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

Validator.messages({
even: 'The value of the field must be an even number.',
status: 'Invalid status.'
});

Validator.messages({
even: 'Even number bharo.',
status: 'Galat Status.'
}, 'pb');



Validator.customMessages({
'status.required': 'Status khali nahi hona chahiye.'
}, 'hi');


Validator.extend('even', async function (field, value) {

if ((parseInt(value) % 2) == 0) {
return true;
}

return false;

});

Validator.extend('status', async function (field, value, args) {

if (args.indexOf(value) >= 0) {
return true;
}

return false;

});

let r = {};



// describe('Custom Messages', function () {

// it('should return nested field message', async () => {

// let v = new Validator(
// { org: { name: "" } },
// { org: 'required|object', 'org.name': 'required|string' },
// { 'org.name': 'The compaany name filed is required' }
// );

// let matched = await v.check();

// //throw v.errors;

// // assert.equal(matched, true);

// });


// });

0 comments on commit 47f6c18

Please sign in to comment.