@darkwolf/validator
Advanced tools
Comparing version 2.1.0 to 2.1.1
58
index.js
@@ -198,2 +198,13 @@ class Validator { | ||
_isHas(value, key) { | ||
if (this._isObject(value)) { | ||
if (this._isArray(value) || this._isSet(value)) { | ||
return this._isRange(key, 0, value.length || value.size) | ||
} | ||
if (this._isMap(value)) return value.has(key) | ||
return value.hasOwnProperty(key) | ||
} | ||
return false | ||
} | ||
_isIncludes(value1, value2) { | ||
@@ -212,13 +223,2 @@ if (this._isArray(value1)) return value1.includes(value2) | ||
_isHas(value, key) { | ||
if (this._isObject(value)) { | ||
if (this._isArray(value) || this._isSet(value)) { | ||
return this._isRange(key, 0, value.length || value.size) | ||
} | ||
if (this._isMap(value)) return value.has(key) | ||
return value.hasOwnProperty(key) | ||
} | ||
return false | ||
} | ||
_isUnique(value) { | ||
@@ -239,2 +239,18 @@ if (this._isObject(value)) { | ||
_isUUID(value) { | ||
return this._isRegex(value, /^[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$/i) | ||
} | ||
_isUrl(value) { | ||
return this._isRegex(value, /^(https?:\/\/)?((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3}))(\:\d+)?(\/[\w-.%+@&:~]*)*(\?[\w-.%+@&=:;,~]*)?(\#[\w-]*)?$/i) | ||
} | ||
_isEmail(value) { | ||
return this._isRegex(value, /^[\w-.]+@(([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}$/i) | ||
} | ||
_isPhoneNumber(value) { | ||
return this._isRegex(value, /^\+[1-9]\d{6,14}$/) | ||
} | ||
_valid(callback) { | ||
@@ -474,4 +490,24 @@ if (!this._isOptional) { | ||
} | ||
isUUID(...args) { | ||
if (args.length) return this._isUUID(...args) | ||
return this._valid(() => this._isUUID(this.value)) | ||
} | ||
isUrl(...args) { | ||
if (args.length) return this._isUrl(...args) | ||
return this._valid(() => this._isUrl(this.value)) | ||
} | ||
isEmail(...args) { | ||
if (args.length) return this._isEmail(...args) | ||
return this._valid(() => this._isEmail(this.value)) | ||
} | ||
isPhoneNumber(...args) { | ||
if (args.length) return this._isPhoneNumber(...args) | ||
return this._valid(() => this._isPhoneNumber(this.value)) | ||
} | ||
} | ||
module.exports = new Validator() |
{ | ||
"name": "@darkwolf/validator", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Validator Utility", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -74,1 +74,5 @@ # Validator Utility | ||
### isUnique(value?) | ||
### isUUID(value?) | ||
### isUrl(value?) | ||
### isEmail(value?) | ||
### isPhoneNumber(value?) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16440
406
78