@darkwolf/validator
Advanced tools
Comparing version 2.0.6 to 2.0.7
89
index.js
@@ -17,3 +17,4 @@ class Validator { | ||
call(callback) { | ||
return callback(this) | ||
const value = callback(this) | ||
return this._isUndefined(value) ? this : value | ||
} | ||
@@ -169,2 +170,11 @@ | ||
_isEmpty(value) { | ||
if (this._isObject(value)) { | ||
if (this._isArray(value)) return !!value.length | ||
if (this._isSet(value)) return !!value.size | ||
return !!Object.keys(value).length | ||
} | ||
return false | ||
} | ||
_valid(callback) { | ||
@@ -180,3 +190,3 @@ if (!this._isOptional) { | ||
isType(...args) { | ||
if (this._isUndefined(this.value)) return this._isType(...args) | ||
if (args.length > 1) return this._isType(...args) | ||
return this._valid(() => this._isType(this.value, ...args)) | ||
@@ -186,3 +196,3 @@ } | ||
isObject(...args) { | ||
if (this._isUndefined(this.value)) return this._isObject(...args) | ||
if (args.length) return this._isObject(...args) | ||
return this._valid(() => this._isObject(this.value)) | ||
@@ -192,3 +202,3 @@ } | ||
isUndefined(...args) { | ||
if (this._isUndefined(this.value)) return this._isUndefined(...args) | ||
if (args.length) return this._isUndefined(...args) | ||
return this._valid(() => this._isUndefined(this.value)) | ||
@@ -198,3 +208,3 @@ } | ||
isBoolean(...args) { | ||
if (this._isUndefined(this.value)) return this._isBoolean(...args) | ||
if (args.length) return this._isBoolean(...args) | ||
return this._valid(() => this._isBoolean(this.value)) | ||
@@ -204,3 +214,3 @@ } | ||
isNumber(...args) { | ||
if (this._isUndefined(this.value)) return this._isNumber(...args) | ||
if (args.length) return this._isNumber(...args) | ||
return this._valid(() => this._isNumber(this.value)) | ||
@@ -210,3 +220,3 @@ } | ||
isString(...args) { | ||
if (this._isUndefined(this.value)) return this._isString(...args) | ||
if (args.length) return this._isString(...args) | ||
return this._valid(() => this._isString(this.value)) | ||
@@ -216,3 +226,3 @@ } | ||
isFunction(...args) { | ||
if (this._isUndefined(this.value)) return this._isFunction(...args) | ||
if (args.length) return this._isFunction(...args) | ||
return this._valid(() => this._isFunction(this.value)) | ||
@@ -222,3 +232,3 @@ } | ||
isSymbol(...args) { | ||
if (this._isUndefined(this.value)) return this._isSymbol(...args) | ||
if (args.length) return this._isSymbol(...args) | ||
return this._valid(() => this._isSymbol(this.value)) | ||
@@ -228,3 +238,3 @@ } | ||
isNull(...args) { | ||
if (this._isUndefined(this.value)) return this._isNull(...args) | ||
if (args.length) return this._isNull(...args) | ||
return this._valid(() => this._isNull(this.value)) | ||
@@ -234,3 +244,3 @@ } | ||
isInstance(...args) { | ||
if (this._isUndefined(this.value)) return this._isInstance(...args) | ||
if (args.length > 1) return this._isInstance(...args) | ||
return this._valid(() => this._isInstance(this.value, ...args)) | ||
@@ -240,3 +250,3 @@ } | ||
isArray(...args) { | ||
if (this._isUndefined(this.value)) return this._isArray(...args) | ||
if (args.length) return this._isArray(...args) | ||
return this._valid(() => this._isArray(this.value)) | ||
@@ -246,3 +256,3 @@ } | ||
isBuffer(...args) { | ||
if (this._isUndefined(this.value)) return this._isBuffer(...args) | ||
if (args.length) return this._isBuffer(...args) | ||
return this._valid(() => this._isBuffer(this.value)) | ||
@@ -252,3 +262,3 @@ } | ||
isArrayBuffer(...args) { | ||
if (this._isUndefined(this.value)) return this._isArrayBuffer(...args) | ||
if (args.length) return this._isArrayBuffer(...args) | ||
return this._valid(() => this._isArrayBuffer(this.value)) | ||
@@ -258,3 +268,3 @@ } | ||
isRegExp(...args) { | ||
if (this._isUndefined(this.value)) return this._isRegExp(...args) | ||
if (args.length) return this._isRegExp(...args) | ||
return this._valid(() => this._isRegExp(this.value)) | ||
@@ -264,3 +274,3 @@ } | ||
isSet(...args) { | ||
if (this._isUndefined(this.value)) return this._isSet(...args) | ||
if (args.length) return this._isSet(...args) | ||
return this._valid(() => this._isSet(this.value)) | ||
@@ -270,3 +280,3 @@ } | ||
isObjectExact(...args) { | ||
if (this._isUndefined(this.value)) return this._isObjectExact(...args) | ||
if (args.length) return this._isObjectExact(...args) | ||
return this._valid(() => this._isObjectExact(this.value)) | ||
@@ -276,3 +286,3 @@ } | ||
isExists(...args) { | ||
if (this._isUndefined(this.value)) return this._isExists(...args) | ||
if (args.length) return this._isExists(...args) | ||
return this._valid(() => this._isExists(this.value)) | ||
@@ -282,3 +292,3 @@ } | ||
isNaN(...args) { | ||
if (this._isUndefined(this.value)) return this._isNaN(...args) | ||
if (args.length) return this._isNaN(...args) | ||
return this._valid(() => this._isNaN(this.value)) | ||
@@ -288,3 +298,3 @@ } | ||
isFinite(...args) { | ||
if (this._isUndefined(this.value)) return this._isFinite(...args) | ||
if (args.length) return this._isFinite(...args) | ||
return this._valid(() => this._isFinite(this.value)) | ||
@@ -294,3 +304,3 @@ } | ||
isInteger(...args) { | ||
if (this._isUndefined(this.value)) return this._isInteger(...args) | ||
if (args.length) return this._isInteger(...args) | ||
return this._valid(() => this._isInteger(this.value)) | ||
@@ -300,3 +310,3 @@ } | ||
isSafeInteger(...args) { | ||
if (this._isUndefined(this.value)) return this._isSafeInteger(...args) | ||
if (args.length) return this._isSafeInteger(...args) | ||
return this._valid(() => this._isSafeInteger(this.value)) | ||
@@ -306,3 +316,3 @@ } | ||
isFloat(...args) { | ||
if (this._isUndefined(this.value)) return this._isFloat(...args) | ||
if (args.length) return this._isFloat(...args) | ||
return this._valid(() => this._isFloat(this.value)) | ||
@@ -312,3 +322,3 @@ } | ||
isInfinity(...args) { | ||
if (this._isUndefined(this.value)) return this._isInfinity(...args) | ||
if (args.length) return this._isInfinity(...args) | ||
return this._valid(() => this._isInfinity(this.value)) | ||
@@ -318,3 +328,3 @@ } | ||
isMore(...args) { | ||
if (this._isUndefined(this.value)) return this._isMore(...args) | ||
if (args.length > 1) return this._isMore(...args) | ||
return this._valid(() => this._isMore(this.value, ...args)) | ||
@@ -324,3 +334,3 @@ } | ||
isLess(...args) { | ||
if (this._isUndefined(this.value)) return this._isLess(...args) | ||
if (args.length > 1) return this._isLess(...args) | ||
return this._valid(() => this._isLess(this.value, ...args)) | ||
@@ -330,3 +340,3 @@ } | ||
isEqual(...args) { | ||
if (this._isUndefined(this.value)) return this._isEqual(...args) | ||
if (args.length > 1) return this._isEqual(...args) | ||
return this._valid(() => this._isEqual(this.value, ...args)) | ||
@@ -336,3 +346,3 @@ } | ||
isMoreEqual(...args) { | ||
if (this._isUndefined(this.value)) return this._isMoreEqual(...args) | ||
if (args.length > 1) return this._isMoreEqual(...args) | ||
return this._valid(() => this._isMoreEqual(this.value, ...args)) | ||
@@ -342,3 +352,3 @@ } | ||
isLessEqual(...args) { | ||
if (this._isUndefined(this.value)) return this._isLessEqual(...args) | ||
if (args.length > 1) return this._isLessEqual(...args) | ||
return this._valid(() => this._isLessEqual(this.value, ...args)) | ||
@@ -348,3 +358,3 @@ } | ||
isRange(...args) { | ||
if (this._isUndefined(this.value)) return this._isRange(...args) | ||
if (args.length > 2) return this._isRange(...args) | ||
return this._valid(() => this._isRange(this.value, ...args)) | ||
@@ -354,3 +364,3 @@ } | ||
isTrue(...args) { | ||
if (this._isUndefined(this.value)) return this._isTrue(...args) | ||
if (args.length) return this._isTrue(...args) | ||
return this._valid(() => this._isTrue(this.value)) | ||
@@ -360,3 +370,3 @@ } | ||
isFalse(...args) { | ||
if (this._isUndefined(this.value)) return this._isFalse(...args) | ||
if (args.length) return this._isFalse(...args) | ||
return this._valid(() => this._isFalse(this.value)) | ||
@@ -366,3 +376,3 @@ } | ||
isRegex(...args) { | ||
if (this._isUndefined(this.value)) return this._isRegex(...args) | ||
if (args.length) return this._isRegex(...args) | ||
return this._valid(() => this._isRegex(this.value, ...args)) | ||
@@ -372,3 +382,3 @@ } | ||
isRequired(...args) { | ||
if (this._isUndefined(this.value)) return this._isRequired(...args) | ||
if (args.length) return this._isRequired(...args) | ||
return this._valid(() => this._isRequired(this.value)) | ||
@@ -378,13 +388,18 @@ } | ||
isOptional(...args) { | ||
if (this._isUndefined(this.value)) return this._isUndefined(...args) | ||
if (args.length) return this._isUndefined(...args) | ||
this._isOptional = this.isUndefined(this.value) | ||
return this | ||
} | ||
isLength(...args) { | ||
if (this._isUndefined(this.value)) return this._isLength(...args) | ||
if (args.length && this._isUndefined(this.value)) return this._isLength(...args) | ||
return this._valid(() => this._isLength(this.value, ...args)) | ||
} | ||
isEmpty(...args) { | ||
if (args.length) return this._isEmpty(...args) | ||
return this._valid(() => this._isEmpty(this.value)) | ||
} | ||
} | ||
module.exports = new Validator() |
{ | ||
"name": "@darkwolf/validator", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Validator Utility", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -64,1 +64,2 @@ # Validator Utility | ||
### isLength(value?, length? || ...[min, max]) | ||
### isEmpty(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
292
65
12087