
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
feature-toggles
Advanced tools
Simple implementation of feature toggles for JavaScript (also called feature flipping).
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.
Example for using plain values:
// define toggles
var toggles = {foo: true, bar: false};
// load them into the module
var featureToggles = require('feature-toggles');
featureToggles.load(toggles);
// check if a feature is enabled
if (featureToggles.isFeatureEnabled('foo')) {
// do something
}
For computed values provide a function for the value of a feature toggle.
Whenever checking if the feature is enabled the provided function will be invoked.
All arguments passed to the isFeatureEnabled()
call except the first one are passed on to the function.
Example:
// define a computed toggle
var toggles = {
foo: function(a, b) {
return (a == 'a' && b == 'b');
}
}
// load them into the module
var featureToggles = require('feature-toggles');
featureToggles.load(toggles);
// check if a feature is enabled and provide additional arguments
if (featureToggles.isFeatureEnabled('foo', 'a', 'b') {
// do something
}
If the function throws an exception the isFeatureEnabled()
call will return false to prevent runtime crashes.
Enabling a toggle based on an url parameter within an express app:
var toggles = {
foo: function(request) {
return request.param('enableFoo');
}
}
var featureToggles = require('feature-toggles');
featureToggles.load(toggles);
app.get('/', function(request, response) {
if (featureToggles.isFeatureEnabled('foo', request)) {
// do something
}
});
Enabling a toggle based on a certain date:
var toggles = {
foo: function() {
var date = new Date();
return date.getDate() > 15;
}
}
var featureToggles = require('feature-toggles');
featureToggles.load(toggles);
if (featureToggles.isFeatureEnabled('foo')) {
// do something
}
Use the middleware to easily toggle features per request.
This way a special version of isFeatureEnabled()
is exposed to all views (res.locals).
Computed toggles will automatically receive the current request and response as arguments.
var toggles = {
foo: function(request, response) {
return request.param('enableFoo');
}
}
var application = express();
application.use(featureToggles.middleware);
- if (isFeatureEnabled('foo'))
Foo is enabled
FAQs
Feature Toggles for JavaScript
The npm package feature-toggles receives a total of 3,340 weekly downloads. As such, feature-toggles popularity was classified as popular.
We found that feature-toggles demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.