diff --git a/lib/plugins/validation.js b/lib/plugins/validation.js index 4b45dcd9..b5e7863d 100644 --- a/lib/plugins/validation.js +++ b/lib/plugins/validation.js @@ -8,7 +8,6 @@ var comb = require("comb"), isIPv4 = net.isIPv4, isIPv6 = net.isIPv6, validator = require("validator"), - validatorCheck = validator.check, dateCmp = comb.date.compare, isArray = comb.isArray, combDeepEqual = comb.deepEqual, @@ -178,66 +177,61 @@ var Validator = define(null, { isEmail:function isEmail(opts) { return this.__addAction(function (col) { - return validatorCheck(col).isEmail(); + return validator.isEmail(col); }, merge({message:"{col} must be a valid Email Address got {val}"}, opts)); }, isUrl:function isUrl(opts) { return this.__addAction(function (col) { - return validatorCheck(col).isUrl(); + return !!col.match(/^(?:https?|ftp):\/\/localhost/) || validator.isURL(col); }, merge({message:"{col} must be a valid url got {val}"}, opts)); }, isAlpha:function isAlpha(opts) { return this.__addAction(function (col) { - return validatorCheck(col).isAlpha(); + return validator.isAlpha(col); }, merge({message:"{col} must be a only letters got {val}"}, opts)); }, isAlphaNumeric:function isAlphaNumeric(opts) { return this.__addAction(function (col) { - return validatorCheck(col).isAlphanumeric(); + return validator.isAlphanumeric(col); }, merge({message:"{col} must be a alphanumeric got {val}"}, opts)); }, hasLength:function hasLength(min, max, opts) { return this.__addAction(function (col) { - return validatorCheck(col).len(min, max); + return validator.isLength(col, {min: min, max: max}); }, merge({message:"{col} must have a length between " + min + (max ? " and " + max : "") + "."}, opts)); }, isLowercase:function isLowercase(opts) { return this.__addAction(function (col) { - return validatorCheck(col).isLowercase(); + return validator.isLowercase(col); }, merge({message:"{col} must be lowercase got {val}."}, opts)); }, isUppercase:function isUppercase(opts) { return this.__addAction(function (col) { - return validatorCheck(col).isUppercase(); + return validator.isUppercase(col); }, merge({message:"{col} must be uppercase got {val}."}, opts)); }, isEmpty:function isEmpty(opts) { return this.__addAction(function (col) { - try { - validatorCheck(col).notEmpty(); - return false; - } catch (e) { - return true; - } + return validator.isEmpty(col); }, merge({message:"{col} must be empty got {val}."}, opts)); }, isNotEmpty:function isNotEmpty(opts) { return this.__addAction(function (col) { - return validatorCheck(col).notEmpty(); + return !validator.isEmpty(col); }, merge({message:"{col} must not be empty."}, opts)); }, isCreditCard:function isCreditCard(opts) { return this.__addAction(function (col) { - return validatorCheck(col).isCreditCard(); + return validator.isCreditCard(col); }, merge({message:"{col} is an invalid credit card"}, opts)); }, diff --git a/package.json b/package.json index 900bf08b..030b8146 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "patio", "description": "Patio query engine and ORM", - "version": "1.3.0", + "version": "1.4.0", "keywords": [ "ORM", "object relation mapper", @@ -38,7 +38,7 @@ "pg": "4.4.3", "pg-query-stream": "1.0.0", "pg-types": "1.10.0", - "validator": "~1.5.1" + "validator": "~10.3.0" }, "scripts": { "test": "grunt test"