Skip to content

The modern Koa-Style middleware composition helper for `koa-compose`.

License

Notifications You must be signed in to change notification settings

macchiatojs/wrap-koa-compose

Repository files navigation

@macchiatojs/wrap-koa-compose

The modern Koa-Style middleware composition helper for koa-compose.

Installation

# npm
$ npm install @macchiatojs/wrap-koa-compose koa-compose
# yarn
$ yarn add @macchiatojs/wrap-koa-compose koa-compose

Usage

import Middleware from "@macchiatojs/wrap-koa-compose";

const middleware = new Middleware();

middleware.push((ctx, next) => {
  ctx.arr.push(1);
  return next().then(() => {
    ctx.arr.push(6);
  });
});

middleware.push(async (ctx, next) => {
  ctx.arr.push(2);
  await next();
  ctx.arr.push(5);
});

middleware.push((ctx, next) => {
  ctx.arr.push(3);
  next();
  ctx.arr.push(4);
});

const ctx = { arr: [] };

await middleware.compose(ctx);
console.log(ctx.arr.toString() === "1,2,3,4,5,6");
// true

Support

If you have any problem or suggestion please open an issue.

License


MIT © Imed Jaberi

About

The modern Koa-Style middleware composition helper for `koa-compose`.

Resources

License

Stars

Watchers

Forks

Packages

No packages published