@theunderscorer/chain
v1.1.1
Published
This library was generated with [Nx](https://nx.dev) and is part of the Zen, a library collection made by [TheUnderScorer](https://github.com/TheUnderScorer).
Downloads
28
Readme
chain
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.
Install
With pnpm:
pnpm add @theunderscorer/chain
With npm:
npm install @theunderscorer/chain
Usage
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
Building
Run nx build chain
to build the library.
Running unit tests
Run nx test chain
to execute the unit tests via Jest.