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

conditional-middleware

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

conditional-middleware - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

package.json
{
"name": "conditional-middleware",
"version": "0.1.0",
"version": "0.1.1",
"description": "Conditional, composable middleware for connect, express, and other soon-to-be available server modules.",

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

@@ -124,3 +124,3 @@ # conditional-middleware

## But what if the condtion returns false
## But what if the condtion returns false?

@@ -149,2 +149,30 @@ Other modules like [express-conditional-middleware](https://www.npmjs.com/package/express-conditional-middleware) accept a "failure" function for when the condition fails. However, this is not necessary becuase the very next middleware will always run when the condition fails. Continuing with the basic example above, here is how you might handle a simple failure scenario:

});
```
## What about nesting?
Yup, that works too!
```js
const express = require('express');
const conditional = require('conditional-middleware');
const app = express();
app.use(conditional(() => true, [
(req, res, next) => {
req.foo = true;
next();
},
conditional(() => true, [
(req, res, next) => {
req.bar = true;
next();
}
]),
(req, res, next) => {
assert.ok(req.foo, 'foo is set');
assert.ok(req.bar, 'bar is set');
next()
}
]));
```

@@ -184,2 +184,25 @@ const assert = require('chai').assert;

});
describe('nesting conditionals', () => {
it('works', done => {
const middleware = conditional(() => true, [
(req, res, next) => {
req.foo = true;
next();
},
conditional(() => true, [
(req, res, next) => {
req.bar = true;
next();
}
]),
(req, res, next) => {
assert.ok(req.foo, 'foo is set');
assert.ok(req.bar, 'bar is set');
next();
}
]);
middleware({}, {}, done);
});
});
});
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