express-conditional-middleware
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -0,1 +1,3 @@ | ||
var once = require('once'); | ||
/** | ||
@@ -30,2 +32,3 @@ * Returns a middleware that can be used to conditionally execute another | ||
return function (req, res, next) { | ||
next = once(next); | ||
if (condition === true || (typeof condition === 'function' && condition(req, res, next))) { | ||
@@ -32,0 +35,0 @@ return middleware(req, res, next); |
{ | ||
"name": "express-conditional-middleware", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Allow express middlewares to be overridden based on a condition.", | ||
@@ -26,3 +26,6 @@ "repository": "https://github.com/elliotttf/express-conditional-middleware", | ||
} | ||
}, | ||
"dependencies": { | ||
"once": "^1.3.2" | ||
} | ||
} |
@@ -54,4 +54,29 @@ var conditional = require('../lib/conditional.js'); | ||
}); | ||
}, | ||
funcOnce: function (test) { | ||
test.expect(2); | ||
var count = 0; | ||
var conditionFunc = function (req, res, next) { | ||
next(); | ||
return true; | ||
}; | ||
var middleware = conditional( | ||
conditionFunc, | ||
function (req, res, next) { | ||
test.ok(true, 'Conditional executed.'); | ||
next(); | ||
test.done(); | ||
} | ||
); | ||
middleware({}, {}, function () { | ||
count++; | ||
test.equal(count, 1, 'Middleware only executed once.'); | ||
}); | ||
} | ||
}; | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10140
134
1
+ Addedonce@^1.3.2
+ Addedonce@1.4.0(transitive)
+ Addedwrappy@1.0.2(transitive)