Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
gyson committed Oct 22, 2015
1 parent 3e69dd9 commit eda2ba9
Showing 1 changed file with 9 additions and 36 deletions.
45 changes: 9 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,27 @@

# koa-convert

Convert koa generator-based middleware to promise-based middleware.
Convert koa legacy ( v0.x & v1.x ) generator middleware to promise middleware ( v2.x ).

## Installation

```
$ npm install koa-convert
```

## Related Issues

* koa [#415](https://github.com/koajs/koa/issues/415)
* koa-compose [#27](https://github.com/koajs/compose/pull/27)

## Usage

```js
const Koa = require('koa') // koa v2.x
const convert = require('koa-convert')

//
// convert a generator-based middleware to promise-based middleware
//
let promiseBased = convert(function* generatorBased(next) {
yield next
// or
// yield* next
})

//
// convert array of middleware
//
let mws = [
// will convert it to promise-based middleware
function* generatorMW (next) {
yield next
},
// will convert it to promise-based middleware
function* generatorMW(next) {
yield* next
},
// return itself if it's not generator-based middleware
function (ctx, next) {
return next()
},
// return itself if it's not generator-based middleware
async function (ctx, next) {
await next()
},
].map(convert)
let app = new Koa()

app.use(convert(function* legacyMiddleware(next) {
// before
yield next
// after
}))
```

## License
Expand Down

0 comments on commit eda2ba9

Please sign in to comment.