@theunderscorer/chain

1.1.1 • Public • Published

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.

logo.png

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @theunderscorer/chain

Weekly Downloads

22

Version

1.1.1

License

MIT

Unpacked Size

3.84 kB

Total Files

6

Last publish

Collaborators

  • theunderscorer