Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

combine-middlewares

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

combine-middlewares

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

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
540
decreased by-6.57%
Maintainers
1
Weekly downloads
 
Created
Source

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

Usage

const combineMiddlewares = require('combine-middlewares')

recursive async-await

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

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

Keywords

FAQs

Package last updated on 21 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc