Merge pull request 'hotfix/array-check-contains-type' (#20) from hotfix/array-check-contains-type into develop
continuous-integration/drone/push Build is passing Details

Reviewed-on: #20
This commit is contained in:
Jay 2020-07-05 05:31:07 +00:00
commit c767e73f0a
3 changed files with 19 additions and 13 deletions

View File

@ -1,5 +1,9 @@
# ChangeLog
## 2020-07-05 (0.0.7)
- fix array check contains type
## 2020-07-04 (0.0.6)
- add array validate contains type

View File

@ -1,6 +1,6 @@
{
"name": "mtfos-validator",
"version": "0.0.6",
"version": "0.0.7",
"description": "",
"main": "index.js",
"scripts": {

View File

@ -61,20 +61,22 @@ class TypeArray extends Base {
if (this._min !== null && value.length < this._min) return `value length < ${this._min}`
if (this._max !== null && value.length > this._max) return `value length > ${this._max}`
for (const item of value) {
let verified = false
let fail = ''
for (const type of this._itemTypes) {
const result = type.validate(item)
if (result) {
fail = result
} else {
verified = true
fail = ''
break
if (this._itemTypes.length > 0) {
for (const item of value) {
let verified = false
let fail = ''
for (const type of this._itemTypes) {
const result = type.validate(item)
if (result) {
fail = result
} else {
verified = true
fail = ''
break
}
}
if (!verified || fail) return fail || `item type not match`
}
if (!verified || fail) return fail || `item type not match`
}
return null