Skip to content

Latest commit

 

History

History
106 lines (89 loc) · 2.82 KB

README.md

File metadata and controls

106 lines (89 loc) · 2.82 KB

toggle_logo_text

Build & Publish codecov npm GitHub license Maintenance Donate

Motivation

Simple library to separate deployment of features from release time. It uses network accesible files without the need of a server to provide feature toggles.

Installation

add it to your project using npm install togglee --save or yarn add togglee

Usage

import { Togglee } from '../lib'
// or: const { Togglee } = require("togglee")

const url = "https://gist.githubusercontent.com/alvarolorentedev/c469f99bef5a5c0634b4a94a4acd6546/raw/toggles"
const refreshRateSeconds = 5
const defaultValues = [
    {
      type: "release",
      name: "prop",
      value: true,
    },
    {
      type: "release",
      name: "prop2",
      value: true
    },
    {
      type: "context",
      name: "prop3",
      conditions: [
        {
          field: "username",
          value: "user1",
          operation: "eq"
        }
      ]
    }
]

const subject = new Togglee(url, refreshRateSeconds, defaultValues)


setInterval(() => {
    if (subject.isEnabled("prop"))
        console.log("do stuff")
    else
        console.log("dont do stuff")
    if (subject.isEnabled("prop3", {"username": "user1"}))
        console.log("do stuff for user 1")
    else
        console.log("dont do stuff for user 1")
    if (subject.isEnabled("prop3", {"username": "user2"}))
        console.log("do stuff for user 2")
    else
        console.log("dont do stuff for user 2")
        
    console.log("-----------")
}, 10000);

Type of toggles

Release

Simple true/false logical path definition.

{
    type: "release",
    name: "prop",
    value: true,
}

Context

Allows complex logic to decide the outcome of the logical path (example traffic, users, resources available).

{
    type: "context",
    name: "prop3",
    conditions: [
        {
            field: "username",
            value: "user1",
            operation: "eq"
        }
    ]
}

available operations are:

  • 'eq': equal (===)
  • 'ne': not equal (!==)
  • 'gt': greater than (>)
  • 'ge': greater equal (>=)
  • 'lt': lesser than (<)
  • 'le': lesser qqual (<=)