# combine-middlewares

> combine middlewares to one chain, supports async-await and recursive.

Latest version **0.1.0** (published 2017-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install combine-middlewares
pnpm add combine-middlewares
yarn add combine-middlewares
bun add combine-middlewares
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-09-21 |
| First published | 2017-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Sho Hashimoto |
| Maintainers | shokai |
| Keywords | middleware, chain |

## Links

- npm: https://www.npmjs.com/package/combine-middlewares
- Repository: https://github.com/shokai/combine-middlewares
- Homepage: https://github.com/shokai/combine-middlewares#readme
- Issues: https://github.com/shokai/combine-middlewares/issues
- npm.io page: https://npm.io/package/combine-middlewares

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2017-09-21
- 0.0.3 — 2017-09-15
- 0.0.2 — 2017-09-13
- 0.0.1 — 2017-09-13

## README

# combine-middlewares
combine middlewares to one chain, supports async-await and recursive.

- https://github.com/shokai/combine-middlewares
- https://npmjs.com/package/combine-middlewares

[![CircleCI](https://circleci.com/gh/shokai/combine-middlewares.svg?style=svg)](https://circleci.com/gh/shokai/combine-middlewares)


## Usage

```js
const combineMiddlewares = require('combine-middlewares')
```


### recursive async-await
```js
const double = async (num, next) => {
  await delay(10)
  return next(num * 2)
}
const minus1 = async (num, next) => {
  await delay(10)
  return next(num - 1)
}
const plus10 = async (num, next) => {
  await delay(10)
  return next(num + 10)
}

const [result] = await combineMiddlewares(double, minus1, plus10)(3)
assert.equal(result, 15)
```


### express like

```js
const auth = (req, res, next) => {
  if (!req.user) return res.error('no-user')
  next()
}
const validate = (req, res, next) => {
  if (!/^[a-zA-Z]+$/.test(req.data)) return res.error('no-alphabet')
  next()
}
const upcase = (req, res, next) => {
  res.end(req.data.toUpperCase())
}
const combined = combineMiddlewares(auth, validate, upcase)
```

see more examples in `cd ./test`

---
_Source: https://npm.io/package/combine-middlewares · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
