1.0.2 • Published 6 years ago
cazoo-toggles v1.0.2
Toggles
Simple wrapper on top of environment variables to standardise feature toggling.
This is a universal package for both the browser and node. In the browser the feature toggles can be overriden via localStorage
.
At this point this package is more about estabilishing a convention rather being super useful. In the future this can be extended with pluggable Providers
, like cookies or any service that stores key-value pairs.
Installation
npm install cazoo-toggles --save
Basic usage
Given:
process.env = {
FEATURE_LASER: 'on',
FEATURE_DEATH_STAR: 'off'
}
Then:
import toggles from 'cazoo-toggles';
const { featureIsEnabled } = toggles.create();
...
if (featureIsEnabled('LASER')) {
// use laser
} else {
// don't use laser
}
On the client side, i.e. in the browser you can then override the feature flag by setting the same key in localStorage
.
In console:
localStorage.setItem('FEATURE_DEATH_STAR', 'on');