Skip to content

Commit

Permalink
Fix matches and format parameter order
Browse files Browse the repository at this point in the history
  • Loading branch information
nettofarah committed Feb 4, 2016
1 parent 7c5779d commit 3ec745c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### 0.1.2(Feb 3, 2016)
- Fix `matches` and `format` parameter order

### 0.1.1(Jan 28, 2016)
- Only include relevant files to release

Expand Down
10 changes: 5 additions & 5 deletions lib/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ validations.isCurrency = function isCurrency(paramName, options) {
return checkParam(paramName, 'should look like currency', validator.isCurrency, options);
}

// TODO: write more tests (from isDate to matches)
validations.matches = validations.format = function matches(paramName, pattern) {
return checkParam(paramName, 'should match ' + pattern.toString(), validator.matches, pattern);
}

// TODO: write more tests (from isDate to isUUID)
validations.isDate = function isDate(paramName) {
return checkParam(paramName, 'should be a date', validator.isDate);
}
Expand Down Expand Up @@ -93,10 +97,6 @@ validations.isUUID = function isUUID(paramName, version) {
return checkParam(paramName, 'should be an UUID', validator.isUUID, version);
}

validations.matches = function matches(paramName, pattern) {
return checkParam(paramName, 'should match ' + pattern.toString(), validator.pattern, modifiers);
}

// TODO: Implement these validators
//
// isAfter(paramName [, date])
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": "property-validator",
"version": "0.1.1",
"version": "0.1.2",
"description": "Easy property validation for JavaScript, Node and Express.",
"main": "index.js",
"homepage": "http://github.com/nettofarah/property-validator",
Expand Down
10 changes: 10 additions & 0 deletions test/validation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,14 @@ describe('Validation Helpers', function() {
t(v.isCurrency('i')({ i: '$10,123.45' }));
f(v.isCurrency('i')({ i: 'bla' }));
});

it('matches', function() {
t(v.matches('i', /\d+/)({ i: '123' }));
t(v.matches('i', /\w+/)({ i: 'bla' }));
f(v.matches('i', /\d+/)({ i: 'bla' }));

t(v.format('i', /\d+/)({ i: '123' }));
t(v.format('i', /\w+/)({ i: 'bla' }));
f(v.format('i', /\d+/)({ i: 'bla' }));
});
});

0 comments on commit 3ec745c

Please sign in to comment.