@darkwolf/validator
Advanced tools
Comparing version 2.0.5 to 2.0.6
115
index.js
@@ -141,2 +141,10 @@ class Validator { | ||
_isTrue(value) { | ||
return this._isEqual(value, true) | ||
} | ||
_isFalse(value) { | ||
return this._isEqual(value, false) | ||
} | ||
_isRegex(value, regex) { | ||
@@ -146,5 +154,22 @@ return regex.test(value) | ||
_isRequired(value) { | ||
return !this._isUndefined(value) | ||
} | ||
_isLength(value, ...args) { | ||
if (this._isString(value) || this._isArray(value)) { | ||
if (args.length) { | ||
if (args.length > 1) return this._isRange(value.length, ...args) | ||
return this._isEqual(value.length, ...args) | ||
} | ||
return !!value.length | ||
} | ||
return false | ||
} | ||
_valid(callback) { | ||
if (this._isUndefined(this.isValid) || this.isValid) { | ||
this.isValid = !!callback() | ||
if (!this._isOptional) { | ||
if (this._isUndefined(this.isValid) || this.isValid) { | ||
this.isValid = !!callback() | ||
} | ||
} | ||
@@ -155,3 +180,3 @@ return this | ||
isType(...args) { | ||
if (args.length > 1) return this._isType(...args) | ||
if (this._isUndefined(this.value)) return this._isType(...args) | ||
return this._valid(() => this._isType(this.value, ...args)) | ||
@@ -161,3 +186,3 @@ } | ||
isObject(...args) { | ||
if (args.length) return this._isObject(...args) | ||
if (this._isUndefined(this.value)) return this._isObject(...args) | ||
return this._valid(() => this._isObject(this.value)) | ||
@@ -167,3 +192,3 @@ } | ||
isUndefined(...args) { | ||
if (args.length) return this._isUndefined(...args) | ||
if (this._isUndefined(this.value)) return this._isUndefined(...args) | ||
return this._valid(() => this._isUndefined(this.value)) | ||
@@ -173,3 +198,3 @@ } | ||
isBoolean(...args) { | ||
if (args.length) return this._isBoolean(...args) | ||
if (this._isUndefined(this.value)) return this._isBoolean(...args) | ||
return this._valid(() => this._isBoolean(this.value)) | ||
@@ -179,3 +204,3 @@ } | ||
isNumber(...args) { | ||
if (args.length) return this._isNumber(...args) | ||
if (this._isUndefined(this.value)) return this._isNumber(...args) | ||
return this._valid(() => this._isNumber(this.value)) | ||
@@ -185,3 +210,3 @@ } | ||
isString(...args) { | ||
if (args.length) return this._isString(...args) | ||
if (this._isUndefined(this.value)) return this._isString(...args) | ||
return this._valid(() => this._isString(this.value)) | ||
@@ -191,3 +216,3 @@ } | ||
isFunction(...args) { | ||
if (args.length) return this._isFunction(...args) | ||
if (this._isUndefined(this.value)) return this._isFunction(...args) | ||
return this._valid(() => this._isFunction(this.value)) | ||
@@ -197,3 +222,3 @@ } | ||
isSymbol(...args) { | ||
if (args.length) return this._isSymbol(...args) | ||
if (this._isUndefined(this.value)) return this._isSymbol(...args) | ||
return this._valid(() => this._isSymbol(this.value)) | ||
@@ -203,3 +228,3 @@ } | ||
isNull(...args) { | ||
if (args.length) return this._isNull(...args) | ||
if (this._isUndefined(this.value)) return this._isNull(...args) | ||
return this._valid(() => this._isNull(this.value)) | ||
@@ -209,3 +234,3 @@ } | ||
isInstance(...args) { | ||
if (args.length > 1) return this._isInstance(...args) | ||
if (this._isUndefined(this.value)) return this._isInstance(...args) | ||
return this._valid(() => this._isInstance(this.value, ...args)) | ||
@@ -215,3 +240,3 @@ } | ||
isArray(...args) { | ||
if (args.length) return this._isArray(...args) | ||
if (this._isUndefined(this.value)) return this._isArray(...args) | ||
return this._valid(() => this._isArray(this.value)) | ||
@@ -221,3 +246,3 @@ } | ||
isBuffer(...args) { | ||
if (args.length) return this._isBuffer(...args) | ||
if (this._isUndefined(this.value)) return this._isBuffer(...args) | ||
return this._valid(() => this._isBuffer(this.value)) | ||
@@ -227,3 +252,3 @@ } | ||
isArrayBuffer(...args) { | ||
if (args.length) return this._isArrayBuffer(...args) | ||
if (this._isUndefined(this.value)) return this._isArrayBuffer(...args) | ||
return this._valid(() => this._isArrayBuffer(this.value)) | ||
@@ -233,3 +258,3 @@ } | ||
isRegExp(...args) { | ||
if (args.length) return this._isRegExp(...args) | ||
if (this._isUndefined(this.value)) return this._isRegExp(...args) | ||
return this._valid(() => this._isRegExp(this.value)) | ||
@@ -239,3 +264,3 @@ } | ||
isSet(...args) { | ||
if (args.length) return this._isSet(...args) | ||
if (this._isUndefined(this.value)) return this._isSet(...args) | ||
return this._valid(() => this._isSet(this.value)) | ||
@@ -245,3 +270,3 @@ } | ||
isObjectExact(...args) { | ||
if (args.length) return this._isObjectExact(...args) | ||
if (this._isUndefined(this.value)) return this._isObjectExact(...args) | ||
return this._valid(() => this._isObjectExact(this.value)) | ||
@@ -251,3 +276,3 @@ } | ||
isExists(...args) { | ||
if (args.length) return this._isExists(...args) | ||
if (this._isUndefined(this.value)) return this._isExists(...args) | ||
return this._valid(() => this._isExists(this.value)) | ||
@@ -257,3 +282,3 @@ } | ||
isNaN(...args) { | ||
if (args.length) return this._isNaN(...args) | ||
if (this._isUndefined(this.value)) return this._isNaN(...args) | ||
return this._valid(() => this._isNaN(this.value)) | ||
@@ -263,3 +288,3 @@ } | ||
isFinite(...args) { | ||
if (args.length) return this._isFinite(...args) | ||
if (this._isUndefined(this.value)) return this._isFinite(...args) | ||
return this._valid(() => this._isFinite(this.value)) | ||
@@ -269,3 +294,3 @@ } | ||
isInteger(...args) { | ||
if (args.length) return this._isInteger(...args) | ||
if (this._isUndefined(this.value)) return this._isInteger(...args) | ||
return this._valid(() => this._isInteger(this.value)) | ||
@@ -275,3 +300,3 @@ } | ||
isSafeInteger(...args) { | ||
if (args.length) return this._isSafeInteger(...args) | ||
if (this._isUndefined(this.value)) return this._isSafeInteger(...args) | ||
return this._valid(() => this._isSafeInteger(this.value)) | ||
@@ -281,3 +306,3 @@ } | ||
isFloat(...args) { | ||
if (args.length) return this._isFloat(...args) | ||
if (this._isUndefined(this.value)) return this._isFloat(...args) | ||
return this._valid(() => this._isFloat(this.value)) | ||
@@ -287,3 +312,3 @@ } | ||
isInfinity(...args) { | ||
if (args.length) return this._isInfinity(...args) | ||
if (this._isUndefined(this.value)) return this._isInfinity(...args) | ||
return this._valid(() => this._isInfinity(this.value)) | ||
@@ -293,3 +318,3 @@ } | ||
isMore(...args) { | ||
if (args.length > 1) return this._isMore(...args) | ||
if (this._isUndefined(this.value)) return this._isMore(...args) | ||
return this._valid(() => this._isMore(this.value, ...args)) | ||
@@ -299,3 +324,3 @@ } | ||
isLess(...args) { | ||
if (args.length > 1) return this._isLess(...args) | ||
if (this._isUndefined(this.value)) return this._isLess(...args) | ||
return this._valid(() => this._isLess(this.value, ...args)) | ||
@@ -305,3 +330,3 @@ } | ||
isEqual(...args) { | ||
if (args.length > 1) return this._isEqual(...args) | ||
if (this._isUndefined(this.value)) return this._isEqual(...args) | ||
return this._valid(() => this._isEqual(this.value, ...args)) | ||
@@ -311,3 +336,3 @@ } | ||
isMoreEqual(...args) { | ||
if (args.length > 1) return this._isMoreEqual(...args) | ||
if (this._isUndefined(this.value)) return this._isMoreEqual(...args) | ||
return this._valid(() => this._isMoreEqual(this.value, ...args)) | ||
@@ -317,3 +342,3 @@ } | ||
isLessEqual(...args) { | ||
if (args.length > 1) return this._isLessEqual(...args) | ||
if (this._isUndefined(this.value)) return this._isLessEqual(...args) | ||
return this._valid(() => this._isLessEqual(this.value, ...args)) | ||
@@ -323,12 +348,38 @@ } | ||
isRange(...args) { | ||
if (args.length > 2) return this._isRange(...args) | ||
if (this._isUndefined(this.value)) return this._isRange(...args) | ||
return this._valid(() => this._isRange(this.value, ...args)) | ||
} | ||
isTrue(...args) { | ||
if (this._isUndefined(this.value)) return this._isTrue(...args) | ||
return this._valid(() => this._isTrue(this.value)) | ||
} | ||
isFalse(...args) { | ||
if (this._isUndefined(this.value)) return this._isFalse(...args) | ||
return this._valid(() => this._isFalse(this.value)) | ||
} | ||
isRegex(...args) { | ||
if (args.length > 1) return this._isRegex(...args) | ||
if (this._isUndefined(this.value)) return this._isRegex(...args) | ||
return this._valid(() => this._isRegex(this.value, ...args)) | ||
} | ||
isRequired(...args) { | ||
if (this._isUndefined(this.value)) return this._isRequired(...args) | ||
return this._valid(() => this._isRequired(this.value)) | ||
} | ||
isOptional(...args) { | ||
if (this._isUndefined(this.value)) return this._isUndefined(...args) | ||
this._isOptional = this.isUndefined(this.value) | ||
return this | ||
} | ||
isLength(...args) { | ||
if (this._isUndefined(this.value)) return this._isLength(...args) | ||
return this._valid(() => this._isLength(this.value, ...args)) | ||
} | ||
} | ||
module.exports = new Validator() |
{ | ||
"name": "@darkwolf/validator", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Validator Utility", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,2 +45,4 @@ # Validator Utility | ||
### isObjectExact(value?) | ||
### isTrue(value?) | ||
### isFalse(value?) | ||
### isExists(value?) | ||
@@ -60,1 +62,4 @@ ### isNaN(value?) | ||
### isRegex(value?, regex) | ||
### isRequired(value?) | ||
### isOptional(value?) | ||
### isLength(value?, length? || ...[min, max]) |
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
12198
279
64