UNPKG

@clipboard-health/rules-engine

Version:

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

18 lines 529 B
"use strict"; 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((r) => r.runIf(context.input)); return rule ? rule.run(context) : context; }, }; } //# sourceMappingURL=firstMatch.js.map