@darkwolf/validator
Advanced tools
Comparing version 2.0.9 to 2.1.0
54
index.js
@@ -198,6 +198,41 @@ class Validator { | ||
_isIncluded(value, array) { | ||
return array.includes(value) | ||
_isIncludes(value1, value2) { | ||
if (this._isArray(value1)) return value1.includes(value2) | ||
if (this._isSet(value1)) return value1.has(value2) | ||
if (this._isMap(value1)) { | ||
return Array.from(value1).some(([key, value]) => value === value2) | ||
} | ||
return false | ||
} | ||
_isIncluded(value1, value2) { | ||
return this._isIncludes(value2, value1) | ||
} | ||
_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) { | ||
if (this._isObject(value)) { | ||
if (this._isArray(value)) { | ||
return this._isEqual(value.length, [...new Set(value)].length) | ||
} | ||
if (this._isSet(value)) return true | ||
if (this._isMap(value)) { | ||
return this._isEqual(value.size, [...new Set(Array.from(value))].length) | ||
} | ||
const values = Object.values(value) | ||
return this._isEqual(values.length, [...new Set(values)].length) | ||
} | ||
return false | ||
} | ||
_valid(callback) { | ||
@@ -418,2 +453,12 @@ if (!this._isOptional) { | ||
isHas(...args) { | ||
if (args.length > 1) return this._isHas(...args) | ||
return this._valid(() => this._isHas(this.value, ...args)) | ||
} | ||
isIncludes(...args) { | ||
if (args.length > 1) return this._isIncludes(...args) | ||
return this._valid(() => this._isIncludes(this.value, ...args)) | ||
} | ||
isIncluded(...args) { | ||
@@ -423,4 +468,9 @@ if (args.length > 1) return this._isIncluded(...args) | ||
} | ||
isUnique(...args) { | ||
if (args.length) return this._isUnique(...args) | ||
return this._valid(() => this._isUnique(this.value)) | ||
} | ||
} | ||
module.exports = new Validator() |
{ | ||
"name": "@darkwolf/validator", | ||
"version": "2.0.9", | ||
"version": "2.1.0", | ||
"description": "Validator Utility", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -70,2 +70,5 @@ # Validator Utility | ||
### isEmpty(value?) | ||
### isHas(value?, key) | ||
### isIncludes(value?, value) | ||
### isIncluded(value?, array) | ||
### isUnique(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
15262
378
74