Skip to content

sunjayaali/compose

Repository files navigation

compose

A function composer utility to generate middleware.

CircleCI Coverage Status codecov

Usage

const compose = require(`@xyluet/compose`);

function fn1(ctx, next) => {
  // you can get value of ctx
  // console.log(ctx);

  console.log(1);
  next();
  console.log(5);
}

function fn2(ctx, next) => {
  console.log(2);
  next();
  console.log(4);
}

const composer = compose([fn1, fn2]);
const middleware = composer({}, (ctx, next) => {
  console.log(3);
});
// will log 1, 2, 3, 4, 5

Install

npm i @xyluet/compose

License

MIT

About

Function composition utility

Resources

License

Stars

Watchers

Forks

Packages

No packages published