UNPKG

@clipboard-health/rules-engine

Version:

A pure functional rules engine to keep logic-dense code simple, reliable, understandable, and explainable.

26 lines 869 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.allIf = allIf; /** * Run all rules that return true for their runIf condition, but only when the predicate function returns true. * * @param allIfPredicate - Function that determines if rules should be evaluated * @param rules - Array of rules to evaluate when predicate is true * @returns A Rule that combines the behavior of all matching rules * * @example * const rule = allIf( * (input) => input.type === 'special', * rule1, * rule2 * ); */ function allIf(allIfPredicate, ...rules) { return { runIf: (input) => allIfPredicate(input), run: (context) => rules .filter((rule) => rule.runIf(context.input)) .reduce((previousContext, rule) => rule.run(previousContext), context), }; } //# sourceMappingURL=allIf.js.map