Skip to content
Middleware composition at new level. Ultimate alternative to `ware`, `plugins`, `koa-compose` and `composition` packages. Allows you to use callbacks, promises, generators and async/await functions as middlewares.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.editorconfig
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE.md
README.md
index.js
package.json
test.js

README.md

vez npmjs.com The MIT License

Middleware composition at new level. Ultimate alternative to ware, plugins, koa-compose and composition packages. Allows you to use callbacks, promises, generators and async/await functions as middlewares.

code climate standard code style travis build status coverage status dependency status

Install

npm i vez --save
npm test

Usage

For more use-cases see the tests

var vez = require('vez')
var assert = require('assert')
var Bluebird = require('bluebird')

vez()
  .use(Bluebird.resolve(123))
  .use(function () {
    assert.deepEqual(this, {a: 'b', c: 'd', e: 'f'})
    return Bluebird.resolve(456)
  })
  .use(function (foo, next) {
    assert.deepEqual(this, {a: 'b', c: 'd', e: 'f'})
    next(null, foo, 789)
  })
  .use(function * (first, second) {
    this.g = first + second
    assert.deepEqual(this, {a: 'b', c: 'd', e: 'f', g: 1245})

    // because generators are handled by `co@4.6`
    return yield {
      gens: this.g
    }
  })
  .run({a: 'b'}, {c: 'd'}, {e: 'f'}, function (err, res) {
    if (err) {
      return console.error(err)
    }
    assert.deepEqual(this, {a: 'b', c: 'd', e: 'f', g: 1245})
    assert.deepEqual(res, [123, 456, [ 456, 789 ], { gens: 1245 }])
    done()
  })

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github

You can’t perform that action at this time.