Javascript Library to use Feature Toggle services
npm install featuretoggle-lib-jsA Javascript client library for interacting with featuretoggle.com. This library is under active development and is likely to change frequently. Bug reports and pull requests are welcome.
Install with Bower
``bash`
bower install featuretoggle-lib-js
Install with NPM
`bash`
npm install featuretoggle-lib-js
`javascript
// Create instance
var ft = new FeatureToggle('customerKey', 'environmentKey', {options});
var myFeature, myFeatures;
// Get features list
ft.getFeatures(function(error,features){
if(error !== null) {
console.log(error);
}
else {
myFeatures = features;
}
});
// Check if specific feature is active
if(myFeatures['feature-name']) {
console.log('Feature is active, run code');
}
// Get status of specific feature
ft.isEnabled('feature-name',function(error,enabled){
if(error !== null) {
console.log(error);
}
else {
myFeature = enabled;
}
});
// Check if single feature is active
if(myFeature) {
console.log('Feature is active, run code');
}
`
`javascript
{
/**
* Authentication token (required)
*
* You can obtained this token from the FeatureToggle backend
*/
auth: 'STRING',
/**
* API version to use (optional, default: '1.0')
*
* WARNING: changing this value may prevent you from accessing
* the API if you supply an invalud version number
*/
version: 'STRING',
/**
* Cache timeout value in seconds (optional, default: 300)
*/
cache_timeout: SECONDS
}
``
Bug reports and pull requests are welcome on GitHub at https://github.com/featuretoggle/lib-js.
The library is available as open source under the terms of the MIT License.