diff --git a/CHANGELOG.md b/CHANGELOG.md index 36daba8..9210501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog + +### 0.2.0(Feb 3, 2016) +- Add `uuid` as an alias for `isUUID` + ### 0.1.2(Feb 3, 2016) - Fix `matches` and `format` parameter order diff --git a/lib/validations.js b/lib/validations.js index ed22867..1d961bd 100644 --- a/lib/validations.js +++ b/lib/validations.js @@ -60,7 +60,11 @@ 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.isUUID = validations.uuid = function isUUID(paramName, version) { + return checkParam(paramName, 'should be an UUID', validator.isUUID, version); +} + +// TODO: write more tests (from isDate to isURL) validations.isDate = function isDate(paramName) { return checkParam(paramName, 'should be a date', validator.isDate); } @@ -93,10 +97,6 @@ validations.isURL = function isURL(paramName, options) { return checkParam(paramName, 'should be an URL', validator.isURL, options); } -validations.isUUID = function isUUID(paramName, version) { - return checkParam(paramName, 'should be an UUID', validator.isUUID, version); -} - // TODO: Implement these validators // // isAfter(paramName [, date]) diff --git a/package.json b/package.json index af725d1..035e95c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "property-validator", - "version": "0.1.2", + "version": "0.2.0", "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 30e1706..99bea30 100644 --- a/test/validation_test.js +++ b/test/validation_test.js @@ -125,4 +125,16 @@ describe('Validation Helpers', function() { t(v.format('i', /\w+/)({ i: 'bla' })); f(v.format('i', /\d+/)({ i: 'bla' })); }); + + it('isUUID / uuid', function() { + t(v.isUUID('i')({ i: 'b7e34a19-1e65-4912-b43f-f68a93d4a1bd' })); + t(v.isUUID('i')({ i: 'A987FBC9-4BED-4078-8F07-9141BA07C9F3' })); + f(v.isUUID('i')({ i: 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3' })); + f(v.isUUID('i')({ i: 'bla' })); + + t(v.uuid('i')({ i: 'b7e34a19-1e65-4912-b43f-f68a93d4a1bd' })); + t(v.uuid('i')({ i: 'A987FBC9-4BED-4078-8F07-9141BA07C9F3' })); + f(v.uuid('i')({ i: 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3' })); + f(v.uuid('i')({ i: 'bla' })); + }); });