This library was generated with Nx and is part of the Zen, a library collection made by TheUnderScorer.
Chain is used to create composable middleware functions, similar to the ones used in Express.js.
With pnpm:
pnpm add @theunderscorer/chain
With npm:
npm install @theunderscorer/chain
import { Chain } from '@theunderscorer/chain';
const chain = new Chain<
(number: number, next: (number: number) => Promise<number>) => Promise<number>
>();
chain.use(async (number, next) => {
console.log('First middleware', number);
const result = await next(number + 1);
console.log('First middleware result', result);
return result;
});
chain.use(async (number, next) => {
console.log('Second middleware', number);
return number + 1;
});
const result = await chain.exec(1);
console.log('Result', result); // 3
Run nx build chain
to build the library.
Run nx test chain
to execute the unit tests via Jest.