Compare commits

...

3 Commits

Author SHA1 Message Date
Jay de1c6e64f5 Merge pull request 'hotfix/array-check-contains-type' (#19) from hotfix/array-check-contains-type into master
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
Reviewed-on: #19
2020-07-05 05:30:42 +00:00
Jay 7d8256a6d6 bump version and changelog
continuous-integration/drone/push Build is passing Details
2020-07-05 05:29:53 +00:00
Jay b282f241a6 [fix] check contains type 2020-07-05 05:29:39 +00:00
3 changed files with 19 additions and 13 deletions

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "mtfos-validator", "name": "mtfos-validator",
"version": "0.0.6", "version": "0.0.7",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "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._min !== null && value.length < this._min) return `value length < ${this._min}`
if (this._max !== null && value.length > this._max) return `value length > ${this._max}` if (this._max !== null && value.length > this._max) return `value length > ${this._max}`
for (const item of value) { if (this._itemTypes.length > 0) {
let verified = false for (const item of value) {
let fail = '' let verified = false
for (const type of this._itemTypes) { let fail = ''
const result = type.validate(item) for (const type of this._itemTypes) {
if (result) { const result = type.validate(item)
fail = result if (result) {
} else { fail = result
verified = true } else {
fail = '' verified = true
break fail = ''
break
}
} }
if (!verified || fail) return fail || `item type not match`
} }
if (!verified || fail) return fail || `item type not match`
} }
return null return null