everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
18 lines (17 loc) • 518 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.chainConditions = void 0;
/**
* Runs the first function where its predicate passes, like functional if/else if.
* @author @dailker
*/
function chainConditions(pairs, defaultFn) {
return (input) => {
for (const [predicate, fn] of pairs) {
if (predicate(input))
return fn(input);
}
return defaultFn(input);
};
}
exports.chainConditions = chainConditions;