JSPM

@teleology/feature-gate

0.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q28850F
  • License MIT

A simple, percent based, sliding feature gate

Package Exports

  • @teleology/feature-gate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@teleology/feature-gate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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'