Socket
Socket
Sign inDemoInstall

middleware-flow

Package Overview
Dependencies
19
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.0 to 0.3.1

71

index.js
var createCount = require('callback-count');
var flow = module.exports = {
series: function (/* middlewares */) {
var args = Array.prototype.slice.call(arguments);
return function (req, res, next) {
var middlewares = args.slice(); // copy
step(middlewares.shift());
var error;
function step (mw) {
if (mw) {
if (error) {
mw(error, req, res, nextStep);
}
else {
mw(req, res, nextStep);
}
}
else {
next(error); // done
}
}
function nextStep (err) {
if (err) {
error = err;
middlewares = middlewares.filter(lengthOf(4));
}
step(middlewares.shift()); // continue
}
};
},
parallel: function (/* middlewares */) {
var args = Array.prototype.slice.call(arguments);
return function (req, res, next) {
var count = createCount(next);
var middlewares = args.slice(); // copy
middlewares.forEach(function () {
count.inc(); // inc first just in case the middlewares are sync
});
middlewares.forEach(function (mw) {
mw(req, res, count.next);
});
};
},
or: function (/* middlewares */) {
var args = Array.prototype.slice.call(arguments);
return function (req, res, next) {
var middlewares = args.slice(); // copy
var firstErr;
step(middlewares.shift());
function step (mw) {
if (mw) {
mw(req, res, nextStep);
}
else {
next(firstErr); // done w/ err or no mw
}
}
function nextStep (err) {
if (err) {
firstErr = firstErr || err;
step(middlewares.shift()); // continue
}
else {
next(); // done
}
}
};
},
series: require('./lib/series'),
parallel: require('./lib/parallel'),
or: require('./lib/or'),
next: function (req, res, next) {

@@ -73,0 +8,0 @@ next();

2

package.json
{
"name": "middleware-flow",
"version": "0.3.0",
"version": "0.3.1",
"description": "Middleware control flow library: series, parallel, or, and",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc