This is a javascript client to be used with the Toogles Feature flag service. It can be used both on the client and on the server. It's a simple wrapper around node-fetch in NodeJS and the Fetch API in the browser.
const Toogles = require('toogles-client');
const toogles = new Toogles('http://server.running.toogles');
toogles.includes('some-feature').then(function(someFeature) {
if (someFeature) {
// Render something to the users that has someFeature-flag set
} else {
// Render something else to the users that doesn't someFeature-flag set
}
});
toogles.includes(['some-feature', 'some-other-feature']).then(function(features) {
....
});
$ npm install --save toogles-client
Download the latest release from this repository and include it in your application with <script>
. To support older browser you must include polyfills for Promise and fetch.
Url to a toogles endpoint
{
headers: {
someHeader: 'to-send'
}
}
If a string is provided a Boolean is returned. If an array is provided an object with feature as key and flag(boolean) as the value:
Example:
Toogles.includes(feature1).then(function(feature1) {
// feature1 = true/false
});
Toogles.includes(['feature1', 'feature2']).then(function(flags) {
// flags = {
// feature1: true/false,
// feature2: true/false
// }
});
If another type than String or Array is provided it will reject.