index.js 995 B

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