UNPKG

@nucypher/taco

Version:

### [`nucypher/taco-web`](../../README.md)

35 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.maxNestedDepth = void 0; const compound_condition_1 = require("./compound-condition"); const if_then_else_condition_1 = require("./if-then-else-condition"); const sequential_1 = require("./sequential"); const maxNestedDepth = (maxDepth) => (condition, currentDepth = 1) => { if (condition.conditionType === compound_condition_1.CompoundConditionType || condition.conditionType === sequential_1.SequentialConditionType || condition.conditionType === if_then_else_condition_1.IfThenElseConditionType) { if (currentDepth > maxDepth) { // no more multi-condition types allowed at this level return false; } if (condition.conditionType === compound_condition_1.CompoundConditionType) { return condition.operands.every((child) => (0, exports.maxNestedDepth)(maxDepth)(child, currentDepth + 1)); } else if (condition.conditionType === sequential_1.SequentialConditionType) { return condition.conditionVariables.every((child) => (0, exports.maxNestedDepth)(maxDepth)(child.condition, currentDepth + 1)); } else { // if-then-else condition const ifThenElseConditions = []; ifThenElseConditions.push(condition.ifCondition); ifThenElseConditions.push(condition.thenCondition); if (typeof condition.elseCondition !== 'boolean') { ifThenElseConditions.push(condition.elseCondition); } return ifThenElseConditions.every((child) => (0, exports.maxNestedDepth)(maxDepth)(child, currentDepth + 1)); } } return true; }; exports.maxNestedDepth = maxNestedDepth; //# sourceMappingURL=multi-condition.js.map