onions
TypeScript icon, indicating that this package has built-in type declarations

4.1.3 • Public • Published

onions

Onions

npm

Intro

Add function middleware in before or after

Install

$ npm install onions --save

Usage

import onions from 'onions';

const before1 = (next) => (a, b) => next(a + 1, b + 1);

const before2 = (next) => async (a, b) => {
    await Promise.resolve();

    next(a + 1, b + 1);
};

const before3 = (next) => (a, b) => next(a + 1, b + 1);

const after = (next) => (...args) => {
    console.log('After');

    next(...args);
};

async function target(a, b) {
    const result = a + b;

    await Promise.resolve();

    return result;
}

(async () => {
  const newTarget = onions(target, [before1, before2, before3], after) // after or [after]

  await newTarget(1, 2); // 9
})();

> 9
> After

Readme

Keywords

Package Sidebar

Install

npm i onions

Weekly Downloads

2

Version

4.1.3

License

ISC

Unpacked Size

8.47 kB

Total Files

6

Last publish

Collaborators

  • evan.yuanzh