Code Monkey home page Code Monkey logo

teleology-feature-gate's Introduction

npm downloads total npm version npm license

@teleology/feature-gate

As there are often various ways of doing things, this library can be used in three ways. Boolean values, rolling values, or array iteration. The use of a secondary unique value as a param is used for consistency.

Installation

npm install --save @teleology/feature-gate

or

yarn add @teleology/feature-gate

Usage

To use the feature gate it needs to be seeded with configuration data. Configuration data entries are defined as a key-value object. Referencing config objects are done with dot-notation.

Rolling Example


A rolling example is any value between 0-1 and can be increased to 'roll-out' features. The rollout is done via a hash of the path as well as the userId, meaning it is both consistent for userIds as well as scaleable.

const factory = require('@teleology/feature-gate');

const USER_ID = 'DE5A50BC-08CE-47C4-B186-D6B29E710188';

const gate = factory({
  showNewWelcome: 0.34,
  showNotifications: 1
});

gate('showNewWelcome', USER_ID) // false

Boolean Example


If you know this value is going to be a boolean, you don't need a unique secondary param.

const factory = require('@teleology/feature-gate');

const USER_ID = 'DE5A50BC-08CE-47C4-B186-D6B29E710188';

const gate = factory({
  features: {
    a: 0.12,
    b: true
  }
});

gate('features.b', USER_ID); // true

A-B(n) Testing Example


Using the same hashing function as the rolling gate, buckets certain users into an array of selections.

const factory = require('@teleology/feature-gate');

const USER_ID = 'DE5A50BC-08CE-47C4-B186-D6B29E710188';

const gate = factory({
  welcome: {
    screens: [
      'A',
      'B',
      'C',
      'D',
    ]
  },
  theme: {
    blue: '0000ff'
  }
});

gate('welcome.screens', USER_ID); // 'A'

teleology-feature-gate's People

Contributors

icarus-sullivan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.