Socket
Socket
Sign inDemoInstall

middleware-flow

Package Overview
Dependencies
1
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 0.2.0

test/conditional.js

70

index.js

@@ -65,4 +65,72 @@ var createCount = require('callback-count');

next();
},
_execConditional: function (conditional) {
return function (req, res, next) {
if (conditional.type === 'middleware') {
conditional.if(req, res, function (err) {
async(err, !err);
});
}
else if (conditional.type === 'async') {
conditional.if(req, res, async);
}
else if (conditional.type === 'sync') {
sync(conditional.if(req, res));
}
else if (conditional.type === 'value') {
sync(conditional.if);
}
else {
throw new Error('unknown conditional type');
}
function sync (result) {
if (result) {
flow.series.apply(null, conditional.then)(req, res, next);
}
else {
flow.series.apply(null, conditional.else)(req, res, next);
}
}
function async (err, result) {
if (err || !result) {
flow.series.apply(null, conditional.else)(req, res, next);
}
else {
flow.series.apply(null, conditional.then)(req, res, next);
}
}
};
},
conditional: function (type, test) {
var conditional = {
type: type,
if: test
};
return thenAndElse(this._execConditional(conditional), conditional);
},
mwIf: function (mw) {
return this.conditional('middleware', mw);
},
syncIf: function (mw) {
return this.conditional('sync', mw);
},
asyncIf: function (mw) {
return this.conditional('async', mw);
},
if: function (val) {
return this.conditional('value', val);
}
};
flow.and = flow.series;
flow.and = flow.series;
function thenAndElse (exec, conditional) {
exec.then = function (/* middlewares */) {
conditional.then = Array.prototype.slice.call(arguments);
return exec;
};
exec.else = function (/* middlewares */) {
conditional.else = Array.prototype.slice.call(arguments);
return exec;
};
return exec;
}

2

package.json
{
"name": "middleware-flow",
"version": "0.1.2",
"version": "0.2.0",
"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