handle arrays correctly in checkMatchesObjectStructure
This commit is contained in:
@@ -13,14 +13,24 @@ export function checkMatchesObjectStructure(
|
|||||||
const actualType = typeof objectToCheck[key];
|
const actualType = typeof objectToCheck[key];
|
||||||
if (requiredType != actualType) return false;
|
if (requiredType != actualType) return false;
|
||||||
|
|
||||||
|
if (Array.isArray(reference[key])) {
|
||||||
|
// only check if array is not empty
|
||||||
|
if (objectToCheck[key].length == 0) continue;
|
||||||
|
|
||||||
|
// check first item of array
|
||||||
|
const requiredType = typeof reference[key][0];
|
||||||
|
const actualType = typeof objectToCheck[key][0];
|
||||||
|
|
||||||
|
if (requiredType != actualType) return false;
|
||||||
|
} else if (requiredType == "object") {
|
||||||
// recurse into objects
|
// recurse into objects
|
||||||
if (requiredType != "object") continue;
|
|
||||||
const doesNestedObjectMatch = checkMatchesObjectStructure(
|
const doesNestedObjectMatch = checkMatchesObjectStructure(
|
||||||
reference[key],
|
reference[key],
|
||||||
objectToCheck[key]
|
objectToCheck[key]
|
||||||
);
|
);
|
||||||
if (doesNestedObjectMatch == false) return false;
|
if (doesNestedObjectMatch == false) return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user