feature-toggles
Advanced tools
Comparing version 1.2.0 to 1.3.0
47
index.js
@@ -1,28 +0,29 @@ | ||
var _toggles = {}; | ||
var featureToggles = { | ||
_toggles: {}, | ||
load: function(toggles) { | ||
this._toggles = toggles; | ||
}, | ||
var slice = Array.prototype.slice; | ||
isFeatureEnabled: function(featureName) { | ||
var toggle = this._toggles[featureName]; | ||
if (typeof toggle == 'function') { | ||
try { | ||
var toggleArguments = slice.call(arguments, 1); | ||
toggle = toggle.apply(this, toggleArguments); | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
} | ||
return toggle === true; | ||
}, | ||
exports.load = function(toggles) { | ||
_toggles = toggles; | ||
}; | ||
exports.isFeatureEnabled = function(name) { | ||
var toggleValue = _toggles[name]; | ||
if (typeof toggleValue == 'function') { | ||
try { | ||
var toggleArguments = slice.call(arguments, 1); | ||
toggleValue = toggleValue.apply(this, toggleArguments); | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
middleware: function(request, response, next) { | ||
response.locals.isFeatureEnabled = function(featureName) { | ||
return featureToggles.isFeatureEnabled(featureName, request, response); | ||
}; | ||
next(); | ||
} | ||
return toggleValue === true; | ||
}; | ||
exports.middleware = function(request, response, next) { | ||
response.locals.isFeatureEnabled = function(name) { | ||
return exports.isFeatureEnabled(name, request, response); | ||
}; | ||
next(); | ||
}; | ||
module.exports = featureToggles; |
{ | ||
"name": "feature-toggles", | ||
"version": "1.2.0", | ||
"description": "Feature Toggles for Node.js", | ||
"version": "1.3.0", | ||
"description": "Feature Toggles for JavaScript", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/alexlawrence/feature-toggles.git", |
@@ -5,8 +5,8 @@ # feature-toggles | ||
[feature toggles](http://martinfowler.com/bliki/FeatureToggle.html) | ||
for Node.js (also called feature flipping). | ||
for JavaScript (also called feature flipping). | ||
### Features | ||
This module offers one additional feature over using a simple plain JavaScript object: | ||
computed feature toggle values in form of functions. | ||
This module encapsulates all calls to check if a certain feature (toggle) is enabled. | ||
Furthermore it provides the possibility to have computed feature toggle values in form of functions. | ||
@@ -13,0 +13,0 @@ ### Simple toggle values |
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
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
9203
156