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

express-unless

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-unless - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

.eslintrc

23

package.json
{
"name": "express-unless",
"description": "Conditionally add a middleware to express with some common patterns.",
"version": "1.0.0",
"version": "2.0.0",
"license": "MIT",

@@ -14,11 +14,22 @@ "repository": {

},
"main": "index.js",
"main": "./dist/index.js",
"scripts": {
"test": "mocha -R spec"
"build": "rm -rf dist && tsc",
"prepare": "npm run build",
"test": "mocha -R spec --require ts-node/register test/**",
"lint": "eslint --fix --ext .ts ./src"
},
"dependencies": {},
"devDependencies": {
"mocha": "~1.11.0",
"chai": "~1.7.0"
"@types/express": "^4.17.13",
"@types/mocha": "^9.1.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"chai": "^4.3.6",
"eslint": "^8.16.0",
"express": "^4.18.1",
"mocha": "^10.0.0",
"prettier": "^2.6.2",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
}
}

@@ -5,3 +5,3 @@ Conditionally skip a middleware when a condition is met.

npm i express-unless --save
npm i express-unless --save

@@ -13,9 +13,8 @@ ## Usage

```javascript
var unless = require('express-unless');
var { unless } = require("express-unless");
var static = express.static(__dirname + '/public');
var static = express.static(__dirname + "/public");
static.unless = unless;
app.use(static.unless({ method: 'OPTIONS' }));
app.use(static.unless({ method: "OPTIONS" }));
```

@@ -27,8 +26,6 @@

module.exports = function (middlewareOptions) {
var mymid = function (req, res, next) {
var mymid = function (req, res, next) {};
};
mymid.unless = require("express-unless");
mymid.unless = require('express-unless');
return mymid;

@@ -40,9 +37,8 @@ };

- `method` it could be an string or an array of strings. If the request method match the middleware will not run.
- `path` it could be an string, a regexp or an array of any of those. It also could be an array of object which is url and methods key-pairs. If the request path or path and method match, the middleware will not run. Check [Examples](#examples) for usage.
- `ext` it could be an string or an array of strings. If the request path ends with one of these extensions the middleware will not run.
- `custom` it must be a function that accepts `req` and returns `true` / `false`. If the function returns true for the given request, the middleware will not run.
- `useOriginalUrl` it should be `true` or `false`, default is `true`. if false, `path` will match against `req.url` instead of `req.originalUrl`. Please refer to [Express API](http://expressjs.com/4x/api.html#request) for the difference between `req.url` and `req.originalUrl`.
- `method` it could be an string or an array of strings. If the request method match the middleware will not run.
- `path` it could be an string, a regexp or an array of any of those. It also could be an array of object which is url and methods key-pairs. If the request path or path and method match, the middleware will not run. Check [Examples](#examples) for usage.
- `ext` it could be an string or an array of strings. If the request path ends with one of these extensions the middleware will not run.
- `custom` it must be a function that accepts `req` and returns `true` / `false`. If the function returns true for the given request, the middleware will not run.
- `useOriginalUrl` it should be `true` or `false`, default is `true`. if false, `path` will match against `req.url` instead of `req.originalUrl`. Please refer to [Express API](http://expressjs.com/4x/api.html#request) for the difference between `req.url` and `req.originalUrl`.
## Examples

@@ -53,8 +49,7 @@

```javascript
app.use(requiresAuth.unless({
path: [
'/index.html',
{ url: '/', methods: ['GET', 'PUT'] }
]
}))
app.use(
requiresAuth.unless({
path: ["/index.html", { url: "/", methods: ["GET", "PUT"] }],
})
);
```

@@ -65,6 +60,8 @@

```javascript
app.use(static.unless(function (req) {
var ext = url.parse(req.originalUrl).pathname.substr(-4);
return !~['.jpg', '.html', '.css', '.js'].indexOf(ext);
}));
app.use(
static.unless(function (req) {
var ext = url.parse(req.originalUrl).pathname.substr(-4);
return !~[".jpg", ".html", ".css", ".js"].indexOf(ext);
})
);
```

@@ -71,0 +68,0 @@

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