Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

characteristic

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

characteristic - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

foo.sh

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;
}

2

package.json
{
"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();
});
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc