Skip to content

rjz/confab-features

Repository files navigation

confab-features

Build Status Coverage Status

Feature gates for confab. Declare a list of features that can be toggled on and off:

var confab = require('confab');
var features = require('confab-features');

var config = confab([
  features([
    'new_ui'
  ])
]);

Run the app with gates set by either a previous transformation or environment overrides:

$ CONFIG_FEATURES_NEW_UI=true \
  node app.js

Then, inside the app, retrieve the feature configurations from a processed confab config:

if (config.features.new_ui) {
  renderNewUi();
}
else {
  renderLegacyUi();
}

The full list of configured features is available by invoking config.features directly:

config.features().forEach(function (feature) {
  console.log(feature.key, feature.description);
});

API

confab-features exports:

features(items: Array<Object|String>, opts: Map<String, any>): Map<String, Boolean>

Note that items may contain both string keys and simple object with a key and (optional) description of the feature:

[
  'new_ui',
  { key: 'new_campaign', description: 'A switch to flip' }
]

opts

Name Type Description
configKey String The config key for 'features' and environment variables (default: 'features')
validate Boolean Throw on undeclared or invalid feature settings (default: true)

Quis configiet ipsos configes?

Development

Clone this repository:

$ git clone git@github.com:rjz/confab-features.git

...and copy, fork, customize, and whatever you need to do.

Testing

Lint and run test suite:

$ npm test

License

MIT