onix-core
Version:
Onix library core
23 lines • 833 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createChainedFunction = void 0;
const tslib_1 = require("tslib");
const isFunction_1 = tslib_1.__importDefault(require("lodash/isFunction"));
const createChainedFunction = (...funcs) => {
return funcs
.filter(f => (isFunction_1.default(f)))
.reduce((acc, f) => {
if (!isFunction_1.default(f)) {
throw new Error('Invalid Argument Type, must only provide functions, undefined, or null.');
}
if (acc === null) {
return f;
}
return function chainedFunction(...args) {
acc.apply(this, args);
f.apply(this, args);
};
}, null);
};
exports.createChainedFunction = createChainedFunction;
//# sourceMappingURL=CreateChainedFunction.js.map