structured-elements
Version:
A TypeScript package for modelling and validating data
39 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isExpectationArray = void 0;
const array_1 = require("./array");
const expectation_1 = require("./expectation");
const isExpectationArray = (api, expectation, warn) => {
if (!(0, array_1.isArray)(expectation)) {
if (warn && api.debugEnabled()) {
api.privateFunctions.debug(`StructuredElements#isExpectationArray expected an array but got:`, {
expectation,
});
}
return false;
}
const failures = [];
expectation.forEach((value, index) => {
if (value === undefined) {
return;
}
if (value === null) {
return;
}
if (!(0, expectation_1.isExpectation)(api, value, warn)) {
failures.push({ index, value });
}
});
if (failures.length === 0) {
return true;
}
if (warn && api.debugEnabled()) {
api.privateFunctions.debug(`StructuredElements#isExpectation found invalid expectation array:`, {
expectation,
failures,
});
}
return false;
};
exports.isExpectationArray = isExpectationArray;
//# sourceMappingURL=expectationArray.js.map