Skip to content

Sensorfactdev/draconarius

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Draconarius

Build Status Coverage Status

Manage (feature)flags like a Roman soldier

Install

yarn add @sensorfactdev/draconarius

Basic usage

const { Draconarius } = require('@sensorfactdev/draconarius');

const flags = {
  foo: true,
};

const draconarius = new Draconarius(flags);

const goodOldFn = () => console.log('old');
const newAmazingFn = () => console.log('new');

const operation = draconarius.isEnabled('foo')
  ? newAmazingFn
  : goodOldFn;

operation(); // => new

Flags as functions

const { pathOr } = require('ramda');
const { Draconarius } = require('@sensorfactdev/draconarius');

const flags = {
  hasOpenPayments: user => pathOr(false, ['metaData', 'hasOpenPayments'], user),
};

const draconarius = new Draconarius(flags);

const user = {
  metaData: { hasOpenPayments: false },
};

const navigation = draconarius.isEnabled('hasOpenPayments', user)
  ? browserHistory.replace('/new-payment/832763877832');
  : browserHistory.replace('/open-payment/98766789023')

Updating flags

const { Draconarius } = require('@sensorfactdev/draconarius');

const flags = {
  foo: true,
  bar: false
};

const draconarius = new Draconarius(flags);

// Update a signle flag
draconarius.updateFlag('foo', false);

// Update multiple flags and add one
draconarius.updateFlag({ foo: true, bar: true, fizz: f => !f });

Getting all flags

const { Draconarius } = require('@sensorfactdev/draconarius');
const { equals } = require('ramda');

const flags = { foo: true, bar: false };
const draconarius = new Draconarius(flags);

console.log(equals(draconarius.getAllFlags(), flags)) // true;

Other resources