express-unless
Advanced tools
Comparing version 1.0.0 to 2.0.0
{ | ||
"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 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
15082
8
353
11
66
1