compose-function
Advanced tools
Comparing version 3.0.1 to 3.0.2
24
index.js
@@ -17,7 +17,3 @@ 'use strict'; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return f(g.apply(null, args)); | ||
return f(g.apply(undefined, arguments)); | ||
}; | ||
@@ -27,24 +23,24 @@ }; | ||
function compose() { | ||
for (var _len2 = arguments.length, functions = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
functions[_key2] = arguments[_key2]; | ||
for (var _len = arguments.length, functions = Array(_len), _key = 0; _key < _len; _key++) { | ||
functions[_key] = arguments[_key]; | ||
} | ||
functions = functions.filter(function (fn) { | ||
var funcs = functions.filter(function (fn) { | ||
return typeof fn === 'function'; | ||
}); | ||
var lastIdx = functions.length - 1; | ||
var lastIdx = funcs.length - 1; | ||
var arity = 0; | ||
if (functions.length <= 0) { | ||
throw new Error('No functions passed'); | ||
if (funcs.length <= 0) { | ||
throw new Error('No funcs passed'); | ||
} | ||
if (lastIdx >= 0 && functions[lastIdx]) { | ||
arity = functions[lastIdx].length; | ||
if (lastIdx >= 0 && funcs[lastIdx]) { | ||
arity = funcs[lastIdx].length; | ||
} | ||
return (0, _arityN2['default'])(functions.reduce(compose2), arity); | ||
return (0, _arityN2['default'])(funcs.reduce(compose2), arity); | ||
} | ||
module.exports = exports['default']; |
import arityN from 'arity-n'; | ||
let compose2 = (f, g) => (...args) => f(g.apply(null, args)); | ||
let compose2 = (f, g) => (...args) => f(g(...args)); | ||
export default function compose(...functions) { | ||
functions = functions.filter((fn) => typeof fn === 'function'); | ||
const funcs = functions.filter(fn => typeof fn === 'function'); | ||
let lastIdx = functions.length - 1; | ||
let lastIdx = funcs.length - 1; | ||
let arity = 0; | ||
if (functions.length <= 0) { | ||
throw new Error('No functions passed'); | ||
if (funcs.length <= 0) { | ||
throw new Error('No funcs passed'); | ||
} | ||
if (lastIdx >= 0 && functions[lastIdx]) { | ||
arity = functions[lastIdx].length; | ||
if (lastIdx >= 0 && funcs[lastIdx]) { | ||
arity = funcs[lastIdx].length; | ||
} | ||
return arityN(functions.reduce(compose2), arity); | ||
return arityN(funcs.reduce(compose2), arity); | ||
} |
{ | ||
"name": "compose-function", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Compose new functions f(g(x))", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,7 @@ | ||
[![Travis](https://img.shields.io/travis/stoeffel/compose-function.svg?style=flat-square)](https://travis-ci.org/stoeffel/compose-function) | ||
[![npm](https://img.shields.io/npm/v/compose-function.svg?style=flat-square)](https://www.npmjs.com/package/compose-function) | ||
[![Dependency Status](https://david-dm.org/stoeffel/compose-function.svg?style=flat-square)](https://david-dm.org/stoeffel/compose-function) | ||
[![Coveralls](https://img.shields.io/coveralls/stoeffel/compose-function.svg?style=flat-square)](https://coveralls.io/github/stoeffel/compose-function) | ||
<h1 align="center">Compose-Function</h1> | ||
@@ -15,8 +21,2 @@ | ||
[![Travis](https://img.shields.io/travis/stoeffel/compose-function.svg?style=flat-square)](https://travis-ci.org/stoeffel/compose-function) | ||
[![npm](https://img.shields.io/npm/v/compose-function.svg?style=flat-square)](https://www.npmjs.com/package/compose-function) | ||
[![Dependency Status](https://david-dm.org/stoeffel/compose-function.svg?style=flat-square)](https://david-dm.org/stoeffel/compose-function) | ||
[![Coveralls](https://img.shields.io/coveralls/stoeffel/compose-function.svg?style=flat-square)](https://coveralls.io/github/stoeffel/compose-function) | ||
Installation | ||
@@ -23,0 +23,0 @@ ------------ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7356
46