Comparing version 1.0.1 to 1.1.0
16
index.js
var maybe = require('maybe-args'); | ||
module.exports = maybe(compose); | ||
var slice = Array.prototype.slice; | ||
function compose(){ | ||
var args = Array.prototype.slice.call(arguments); | ||
var compose = maybe(function (){ | ||
var args = slice.call(arguments); | ||
@@ -12,4 +12,8 @@ if(args.length === 1) return args[0]; | ||
return _compose(args.shift(), compose.apply(this, args)); | ||
} | ||
}) | ||
compose.ltr = function() { | ||
return compose.apply(compose, slice.call(arguments).reverse()); | ||
}; | ||
function _compose(fn2, fn1){ | ||
@@ -19,2 +23,4 @@ return function(arg){ | ||
}; | ||
} | ||
} | ||
module.exports = compose; |
{ | ||
"name": "fn-compose", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "compose an arbitrary number of functions from right to left.", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "https://github.com/wilhelmson/fn-compose.git" | ||
"url": "https://github.com/thunklife/fn-compose.git" | ||
}, | ||
@@ -25,0 +25,0 @@ "readmeFilename": "README.md", |
fn-compose | ||
============= | ||
A simple function to compose an arbitrary number of functions from right to left. | ||
A simple function to compose an arbitrary number of functions from right to left, | ||
or left to right. | ||
@@ -16,3 +17,3 @@ install | ||
``` | ||
```js | ||
var compose = require('fn-compose'), | ||
@@ -24,3 +25,13 @@ mul2 = function mul2(a){ return a * 2 }, | ||
mul2Sub1(5); //=> 9 | ||
``` | ||
There is also a left to right mode, which is exported as `ltr`: | ||
```js | ||
var compose = require('fn-compose').ltr, // Notice the .ltr | ||
mul2 = function mul2(a){ return a * 2 }, | ||
sub1 = function sub1(a){ return a - 1 }, | ||
mul2Sub1 = compose(sub1, mul2); | ||
mul2Sub1(5); //=> 8 | ||
``` | ||
@@ -27,0 +38,0 @@ |
@@ -32,2 +32,10 @@ var test = require('tap').test, | ||
test('should can compose ltr as well', function(t){ | ||
t.plan(1); | ||
var mul = function mul2(a){ return a * 2 }, | ||
sub = function sub1(a){ return a - 1 }, | ||
composed = compose.ltr(sub, mul), | ||
result = composed(5); | ||
t.equals(result, 8); | ||
}) |
2842
49
41