1.0.8 • Published 2 months ago

composer-io v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

This module is developed using and inspired by middleware-io and grammyjs. Huge thanks to negezor and KnorpelSenf for their efforts and contribution to the developer community!

API Reference

Features

  1. Self-Sufficient. The library has zero dependencies.
  2. Reliable. The library is written in TypeScript and covered by tests.
  3. Modern. The library comes with native ESM support
  4. Powerful. Supports following additional features:
    • The library has enough built-in snippets;
    • The middleware chain builder;
    • Supports multi-composition pattern for convenient sequential operations, following the Composite design pattern.
    • Routing support for handling various request paths.

Installation

Node.js 14.0.0 or newer is required

  • Using npm (recommended)
    npm i composer-io
  • Using Yarn
    yarn add composer-io
  • Using pnpm
    pnpm add composer-io

Example usage

import { compose } from 'composer-io';

const composedMiddleware = compose(
  async (context, next) => {
    // Step 1

    await next();

    // Step 4

    // Print the current date from the next middleware
    console.log(context.now);
  },
  async (context, next) => {
    // Step 2

    context.now = Date.now();

    await next();

    // Step 3
  },
);

composedMiddleware({}, () => {
  /* Last handler (next) */
})
  .then(() => {
    console.log('Middleware finished work');
  })
  .catch(console.error);
1.0.8

2 months ago

1.0.7

2 months ago

1.0.6

3 months ago

1.0.5

3 months ago

1.0.4

3 months ago

1.0.3

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago