diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a4b138..36daba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/validations.js b/lib/validations.js index 943d9fd..ed22867 100644 --- a/lib/validations.js +++ b/lib/validations.js @@ -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); } @@ -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]) diff --git a/package.json b/package.json index 0cd8643..af725d1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/validation_test.js b/test/validation_test.js index fca0808..30e1706 100644 --- a/test/validation_test.js +++ b/test/validation_test.js @@ -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' })); + }); });