https://github.com/yuanzhhh/onions
Add function middleware in before or after
https://github.com/yuanzhhh/onions
javascript typescipt
Last synced: 2 months ago
JSON representation
Add function middleware in before or after
- Host: GitHub
- URL: https://github.com/yuanzhhh/onions
- Owner: yuanzhhh
- Created: 2020-03-24T09:13:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T18:10:28.000Z (almost 3 years ago)
- Last Synced: 2024-11-14T10:56:31.806Z (11 months ago)
- Topics: javascript, typescipt
- Language: JavaScript
- Homepage: https://github.com/yuanzhhh/onions
- Size: 1.55 MB
- Stars: 17
- Watchers: 2
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# Onions
## Intro
Add function middleware in before or after## Install
```sh
$ npm install onions --save```
## Usage
```ts | pure
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```