1.1.0 • Published 8 years ago
@f/middleware v1.1.0
middleware
Utility for middleware composition.
Installation
$ npm install @f/middleware
Usage
var middleware = require('@f/middleware')
var pipe = require('ramda').pipe
var powAdd = middleware(composePipe)
.use(Math.pow)
.use(function (arg) {
return arg + 1
})
powAdd(2, 4) // => 17
var powAddMultiply = powAdd.add(function (arg) {
return arg * 2
})
powAddMultiply(2, 4) // => 34
function composePipe(stack) {
return pipe.apply(null, stack)
}
API
middleware(compose, stack)
compose
- compose function with signaturecompose(stack)
stack
- array of middleware
Returns: A function representing the composition of the stack. The composed function additionally has helper properties for manipulating the stack.
- .use(fn): adds
fn
tostack
- .add(fn): immutably add
fn
tostack
- .copy(fn): make copy of stack return new composed function
- .map(fn): map stack over
fn
and return new composed function
License
MIT