From b282f241a638e4ce4c8b5ec1ecd66c020e693d73 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 5 Jul 2020 05:29:39 +0000 Subject: [PATCH 1/2] [fix] check contains type --- types/array.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/types/array.js b/types/array.js index 17c9a27..11a5060 100644 --- a/types/array.js +++ b/types/array.js @@ -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 From 7d8256a6d63038b1a46d749b4e89e526c8bdb6c2 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 5 Jul 2020 05:29:53 +0000 Subject: [PATCH 2/2] bump version and changelog --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f21735a..f111483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index d038914..262e48e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mtfos-validator", - "version": "0.0.6", + "version": "0.0.7", "description": "", "main": "index.js", "scripts": {