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.

License

hybridables/vez

Repository files navigation

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.

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published