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 0.5.0 to 1.0.0

4

index.js

@@ -12,3 +12,3 @@ var URL = require('url');

const result = function (req, res, next) {
const result = async function (req, res, next) {
var url = URL.parse((opts.useOriginalUrl ? req.originalUrl : req.url) || req.url || '', true);

@@ -19,3 +19,3 @@

if (opts.custom) {
skip = skip || opts.custom(req);
skip = skip || (await opts.custom(req));
}

@@ -22,0 +22,0 @@

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

@@ -6,0 +6,0 @@ "repository": {

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

- `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, ithe 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`.

@@ -43,0 +43,0 @@

@@ -7,2 +7,3 @@ var unless = require('..');

req.called = true;
next();
}

@@ -242,4 +243,6 @@

describe('with custom exception', function () {
var mid = testMiddleware.unless(function (req) {
return req.baba;
var mid = testMiddleware.unless({
custom: function (req) {
return req.baba;
}
});

@@ -257,3 +260,3 @@

it('should call the middleware when the custom rule doesnt match', function () {
it('should call the middleware when the custom rule doesnt match', function (done) {
var req = {

@@ -263,6 +266,39 @@ baba: false

mid(req, {}, noop);
mid(req, {}, () => {
assert.ok(req.called);
done();
});
});
});
assert.ok(req.called);
describe('with async custom exception', function () {
var mid = testMiddleware.unless({
custom: async function (req) {
return req.baba;
}
});
it('should not call the middleware when the async custom rule match', function (done) {
var req = {
baba: true
};
mid(req, {}, () => {
assert.notOk(req.called);
done();
});
});
it('should call the middleware when the async custom rule doesnt match', function (done) {
var req = {
baba: false
};
mid(req, {}, () => {
assert.ok(req.called);
done();
});
});
});

@@ -269,0 +305,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