@nucypher/taco
Version:
### [`nucypher/taco-web`](../../README.md)
31 lines • 1.54 kB
JavaScript
import { CompoundConditionType } from './compound-condition';
import { IfThenElseConditionType } from './if-then-else-condition';
import { SequentialConditionType } from './sequential';
export const maxNestedDepth = (maxDepth) => (condition, currentDepth = 1) => {
if (condition.conditionType === CompoundConditionType ||
condition.conditionType === SequentialConditionType ||
condition.conditionType === IfThenElseConditionType) {
if (currentDepth > maxDepth) {
// no more multi-condition types allowed at this level
return false;
}
if (condition.conditionType === CompoundConditionType) {
return condition.operands.every((child) => maxNestedDepth(maxDepth)(child, currentDepth + 1));
}
else if (condition.conditionType === SequentialConditionType) {
return condition.conditionVariables.every((child) => 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) => maxNestedDepth(maxDepth)(child, currentDepth + 1));
}
}
return true;
};
//# sourceMappingURL=multi-condition.js.map