UNPKG

813 BJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.default = void 0;
5/**
6 * Safe chained function
7 *
8 * Will only create a new function if needed,
9 * otherwise will pass back existing functions or null.
10 *
11 * @param {function} functions to chain
12 * @returns {function|null}
13 */
14function createChainedFunction(...funcs) {
15 return funcs.filter(f => f != null).reduce((acc, f) => {
16 if (typeof f !== 'function') {
17 throw new Error('Invalid Argument Type, must only provide functions, undefined, or null.');
18 }
19 if (acc === null) return f;
20 return function chainedFunction(...args) {
21 // @ts-ignore
22 acc.apply(this, args);
23 // @ts-ignore
24 f.apply(this, args);
25 };
26 }, null);
27}
28var _default = createChainedFunction;
29exports.default = _default;
30module.exports = exports.default;
\No newline at end of file