@clipboard-health/rules-engine
Version:
A pure functional rules engine to keep logic-dense code simple, reliable, understandable, and explainable.
18 lines • 535 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.firstMatch = firstMatch;
/**
* Run the first rule that returns true for `runIf`.
*
* @param rules The rules to run.
*/
function firstMatch(...rules) {
return {
runIf: (input) => rules.some((rule) => rule.runIf(input)),
run: (context) => {
const rule = rules.find((rule) => rule.runIf(context.input));
return rule ? rule.run(context) : context;
},
};
}
//# sourceMappingURL=firstMatch.js.map