1.0.3 • Published 7 years ago
simple-file-toggle v1.0.3
Simple File Toggle
This is a simple tool to implement Feature Toggles Pattern on your project, it use a json file to setup your toggles.
You must create a json file named as "toggles.json", in this file you can:
- Set the toggle name;
- Define if the toggle is enabled;
- Define the users that can use it;
- Define the day of week, month or hour that it can be used;
- Define the toggle hierarchy;
Usage
Just install it: $ npm i simple-file-toggle
And write a file "toggles.json", like the example below:
[
{
"name": "toggle1",
"enabled": true,
"users": ["<username>"],
"day": ["sun","mon","tues","wed","thurs","fri","sat"],
"month": ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],
"hour": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],
"children" : [
{
"name": "toggle2",
"enabled": true,
"users": ["<username>"],
"day": ["sun","mon","tues","wed","thurs","fri","sat"],
"month": ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],
"hour": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],
"children" : []
},
{
"name": "toggle3",
"enabled": true,
"users": [],
"day": ["fri"],
"month": ["aug"],
"hour": [6],
"children" : [
{
"name": "toggle4",
"enabled": true,
"users": ["user1"],
"day": ["fri"],
"month": ["aug"],
"hour": [7],
"children" : [
]
},
{
"name": "toggle5",
"enabled": true,
"users": [],
"day": [],
"month": [],
"hour": [],
"children" : [
]
}
]
}
]
}
]
And use it on your code:
var toggleResolve = require('simple-file-toggle');
// if you create a toggles.json with another name or in another directory you
// can inform it as third parameter like this "../mydir/myToggleConfig.json"
if (toggleResolve("toggle4","user1")){
console.log("toggle ativo");
}