express-exorcism
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -8,3 +8,3 @@ 'use strict'; | ||
// Replace router methods (get, post, all ...) with new ones | ||
replaceOriginalMethods: true, | ||
// replaceOriginalMethods: true, | ||
// Group by response variants: (send, json, jsonp, end) | ||
@@ -15,13 +15,17 @@ // groupByResponseMethods: false, | ||
// Do not invoke any response method if result is empty string , false or null, | ||
ignoreEmptyResolvedData: false, | ||
ignoreEmptyResolvedData: true, | ||
// Replace following methods (default: all possible methods plus specific "all") | ||
methodList: methods | ||
methodList: methods, | ||
// When singletonRouter = true, exorcism will spawn wrapped instance of router | ||
// instead of wrapping entire router | ||
singletonRouter: false, | ||
}; | ||
module.exports = function (express, userConfig) { | ||
// Using client's router | ||
var Router = express.Router; | ||
// Mergin default and user configs | ||
var config = Object.assign({}, defaultConfig, userConfig); | ||
var config = Object.assign({}, defaultConfig, userConfig || {}); | ||
// Using client's router | ||
var Router = config.singletonRouter ? express.Router() : express.Router; | ||
// Wraps Router's method with async resolver | ||
@@ -41,6 +45,10 @@ function methodWrapper(routerMethod, responseMethod) { | ||
.then(function (result) { | ||
if (config.ignoreEmptyResolvedData && (result === null || result === undefined || result === false)) { | ||
if ( | ||
(config.ignoreEmptyResolvedData && | ||
(result === null || result === undefined || result === false) | ||
) || | ||
responseMethod === 'none' || | ||
!res[responseMethod] | ||
) { | ||
return; | ||
} else if (responseMethod === 'none' || !res[responseMethod]) { | ||
return; | ||
} else if (responseMethod === 'end') { | ||
@@ -74,6 +82,7 @@ res.end(); | ||
// Replacing original methods | ||
if (config.replaceOriginalMethods) { | ||
//if (config.replaceOriginalMethods) { | ||
Router[method.name] = method.wrapped; | ||
} | ||
//} | ||
}); | ||
return Router; | ||
}; |
{ | ||
"name": "express-exorcism", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
"main": "lib/express-exorcism.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha", | ||
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
}, | ||
"author": "Andrew G Kuznetsov <cav@cav.ru>", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"repository": "cavinsmith/express-exorcism", | ||
"engines": { | ||
@@ -21,5 +23,7 @@ "node": ">=7.5.0" | ||
"chai-http": "^3.0.0", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.14.0", | ||
"express": "^4.16.2" | ||
"express": "^4.16.2", | ||
"mocha-lcov-reporter": "^1.3.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
17098
15
517
6