@avidjs/compose
Version:
Composes an array of middleware functions into a call-able middleware stack.
49 lines (36 loc) • 1.81 kB
Markdown
# @avidjs/compose
[](https://www.npmjs.com/package/@avidjs/compose)

[](https://travis-ci.org/avidjs/compose) [](https://codecov.io/gh/avidjs/compose)
[](https://david-dm.org/avidjs/compose)
[](https://david-dm.org/avidjs/compose?type=dev)
[](https://github.com/avidjs/compose/blob/master/LICENSE)
> Composes an array of middleware functions into a call-able middleware stack.
Essentially, a fork of [`koa-compose`](https://github.com/koajs/compose) that features more exhaustive commenting and doesn't perform type checking for every element in the array argument.
Part of [Avid](https://github.com/avidjs), an attempt to better understand [Koa](http://koajs.com/) and [Express](https://expressjs.com/) by taking them apart.
## Installation
```shell
npm install --save @avidjs/compose
```
## Usage
```javascript
const compose = require('@avidjs/compose');
let fn = compose([
async (ctx, next) => {
console.log('first');
await next();
console.log('sixth');
},
async (ctx, next) => {
console.log('second');
await next();
console.log('fifth');
},
async (ctx, next) => {
console.log('third');
await next();
console.log('fourth');
}
]);
fn({});
```