characteristic
Advanced tools
Comparing version 0.0.1 to 0.0.2
31
index.js
@@ -7,8 +7,8 @@ var yaml = require("js-yaml"), | ||
var api = Object.create(null), | ||
configFilePath = configFilePath || path.join( | ||
currentConfigFilePath = configFilePath, | ||
defaultConfigFilePath = path.join( | ||
process.cwd(), | ||
"config", | ||
(process.NODE_ENV || "development") + ".yml"), | ||
doc = yaml.safeLoad(fs.readFileSync(configFilePath, "utf8")), | ||
features = doc["features"]; | ||
(process.NODE_ENV || "development") + ".yml"); | ||
; | ||
@@ -32,2 +32,23 @@ function contains (featureUsers, user) { | ||
api.reload = function (newConfigPath, callback) { | ||
var doc, configPath; | ||
switch (typeof newConfigPath) { | ||
case "string": | ||
configPath = newConfigPath; | ||
break; | ||
case "function": | ||
callback = newConfigPath; | ||
case "undefined": | ||
default: | ||
configPath = currentConfigFilePath || defaultConfigFilePath; | ||
} | ||
doc = yaml.safeLoad(fs.readFileSync(configPath, "utf8")); | ||
currentConfigFilePath = configPath; | ||
features = doc["features"]; | ||
if (callback) { callback(); } | ||
}; | ||
api.isEnabled = function (feature) { | ||
@@ -62,3 +83,5 @@ var status = features[feature], | ||
api.reload(configFilePath); | ||
return api; | ||
} |
{ | ||
"name": "characteristic", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "feature flag util", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -39,4 +39,11 @@ # Characteristic - Feature flag configuration for Node.js | ||
Using customized configuration file path: | ||
Uses customized configuration file path: | ||
var Feature = require("characteristic")("./foo/custom-config.yml"); | ||
var Feature = require("characteristic")("./foo/custom-config.yml"); | ||
Reload configuration: | ||
Feature.reload(); | ||
// reload with new config path | ||
Feature.reload("./bar/custom-config.yml"); |
@@ -27,3 +27,3 @@ var request = require("supertest"), | ||
} | ||
next(); | ||
@@ -88,3 +88,18 @@ } | ||
.end(test.done); | ||
}, | ||
reloadableConfig: function (test) { | ||
Feature.reload(function () { | ||
test.equal(Feature.isEnabled("flying-phone"), false); | ||
test.done(); | ||
}); | ||
}, | ||
reloadWithNewPath: function (test) { | ||
var newConfigPath = path.join(__dirname, "data", "feature4reload.yml"); | ||
Feature.reload(newConfigPath, function() { | ||
test.ok(Feature.isEnabled("flying-phone")); | ||
test.done(); | ||
}); | ||
} | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
9808
11
193
48
3