togglee
v1.1.1
Published
Simple library to separate deployment of features from release time. It uses network accessible files without the need of a server to provide feature toggles.
Downloads
97
Readme
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 (<=)