index.js
995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = compose;
// istanbul ignore next
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _arityN = require('arity-n');
var _arityN2 = _interopRequireDefault(_arityN);
var compose2 = function compose2(f, g) {
return function () {
return f(g.apply(undefined, arguments));
};
};
function compose() {
for (var _len = arguments.length, functions = Array(_len), _key = 0; _key < _len; _key++) {
functions[_key] = arguments[_key];
}
var funcs = functions.filter(function (fn) {
return typeof fn === 'function';
});
var lastIdx = funcs.length - 1;
var arity = 0;
if (funcs.length <= 0) {
throw new Error('No funcs passed');
}
if (lastIdx >= 0 && funcs[lastIdx]) {
arity = funcs[lastIdx].length;
}
return (0, _arityN2['default'])(funcs.reduce(compose2), arity);
}
module.exports = exports['default'];