Socket
Socket
Sign inDemoInstall

keep-or-skip

Package Overview
Dependencies
0
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

lib/utils.js

18

CHANGELOG.md

@@ -1,11 +0,19 @@

# 1.0.2 / 2018-07-20
# Changelog
* Fixed middleware skipping.
## 1.0.3 / 2018-08-06
# 1.0.1 / 2018-05-12
* Optimizations and refactor.
* Added tests for *checkDebug* utility function.
## 1.0.2 / 2018-07-20
* Fixed condition in *wrap* function to ensure the skipping/execution of the middlewares.
## 1.0.1 / 2018-05-12
* Added support for CI.
# 1.0.0 / 2018-03-31
## 1.0.0 / 2018-03-31
* Initial version of `keep-or-skip` - dynamically execute or skip express middlewares.
* Initial version of `keep-or-skip` - dynamically execute or skip express middlewares.

@@ -0,0 +0,0 @@ /*******************************************************************************

@@ -30,2 +30,9 @@ /*******************************************************************************

var utils = require('./utils')
var noop = utils.noop
var isFunction = utils.isFunction
var isBoolean = utils.isBoolean
var log = utils.log
var checkDebug = utils.checkDebug
/**

@@ -45,3 +52,3 @@ *

* @returns {Function[]} An array of middlewares.
* @version 1.0.2
* @version 1.0.3
* @author Nicola Del Gobbo - Mauro Doganieri

@@ -55,6 +62,5 @@ */

var wrappedMiddlewares = []
var predicateResult
var activeDebug = checkDebug(debug, DEBUG)
wrappedMiddlewares.push(function (req, res, next) {
predicateResult = predicate(req, res, noop)
var predicateResult = predicate(req, res)
if (isBoolean(predicateResult)) {

@@ -84,6 +90,3 @@ skip = !predicateResult

wrappedMiddlewares.push(wrap(middlewares))
} else if (Array.isArray(middlewares)) {
if (middlewares.length === 0) {
throw new KeepOrSkipError(ec.INVALID_MIDDLEWARES_PARAM.message)
}
} else if (Array.isArray(middlewares) && middlewares.length > 0) {
middlewares.forEach(function (m) {

@@ -105,26 +108,2 @@ if (!isFunction(m)) {

function noop() { }
function isFunction(value) {
return typeof value === 'function'
}
function isBoolean(value) {
return value === true ||
value === false ||
Object.prototype.toString.call(value) === '[object Boolean]'
}
function log(msg) {
process.stdout.write('KeepOrSkipWarning: ' + msg)
}
function checkDebug(ld, gd) {
ld = isBoolean(ld) ? ld : null
if (ld === true || (ld === null && gd)) {
return true
}
return false
}
module.exports = keepOrSkip
module.exports = keepOrSkip
{
"name": "keep-or-skip",
"description": "Dynamically execute or skip express middlewares",
"version": "1.0.2",
"version": "1.0.3",
"contributors": [

@@ -6,0 +6,0 @@ {

@@ -36,3 +36,3 @@ # keep-or-skip

```json
"keep-or-skip": "1.0.1"
"keep-or-skip": "1.0.3"
```

@@ -39,0 +39,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc