New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

confi

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

confi - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

tests/conf/dev-test.json

9

History.md
0.4.0 / 2015-03-18
==================
* Exposes process.env
* Allows variable variables :inception:
* Allows multiple config files per environment.
* Removes singleton.
0.3.1 / 2013-05-07

@@ -3,0 +12,0 @@ ==================

50

lib/confi.js

@@ -8,2 +8,4 @@ var fs = require('fs');

var cwd = process.cwd();
var glob = require('glob');
var Mustache = require('mustache');

@@ -17,27 +19,35 @@ var defaults = {

var readConfig = function(configPath, env) {
var f = path.join(configPath, env);
if (exists(f+'.json')) {
return cjson.load(f+'.json');
} else if (exists(f+'.yaml')) {
return yaml.load(fs.readFileSync(f+'.yaml', 'utf8'));
}
return {};
var f = path.join(configPath, env);
var obj = {};
glob.sync(f + '*.{json,yaml}').forEach(function(file) {
if (file.indexOf('.json') !== -1) {
aug(true, obj, cjson.load(file));
} else {
aug(true, obj, yaml.load(fs.readFileSync(file, 'utf8')));
}
});
return obj;
};
var config = null;
var load = function(options) {
if (!config) {
var opts = aug({}, defaults, options);
var defaultConf = readConfig(opts.path, "default");
var envConf = readConfig(opts.path, opts.env);
var userConf = {};
if (opts.userConfig) {
var userConfPath = (typeof opts.userConfig === 'string') ? opts.userConfig : opts.path;
userConf = readConfig(userConfPath, process.env.USER);
}
var config = null;
var opts = aug({}, defaults, options);
config = aug(true, defaultConf, envConf, userConf);
config.env = opts.env;
var defaultConf = readConfig(opts.path, "default");
var envConf = readConfig(opts.path, opts.env);
var userConf = {};
if (opts.userConfig) {
var userConfPath = (typeof opts.userConfig === 'string') ? opts.userConfig : opts.path;
userConf = readConfig(userConfPath, process.env.USER);
}
config = aug(true, defaultConf, envConf, userConf);
config.env = opts.env;
config.ENV = process.env || {};
config = JSON.parse(Mustache.render(JSON.stringify(config), config));
return config;

@@ -44,0 +54,0 @@ };

12

package.json
{
"name": "confi",
"description": "a simple configuration library",
"version": "0.3.1",
"homepage": "https://github.com/jgallen23/confi",
"author": "Greg Allen <@jgaui> (http://jga.me)",
"version": "0.4.0",
"homepage": "https://github.com/firstandthird/confi",
"author": "First+Third",
"repository": {
"type": "git",
"url": "https://github.com/jgallen23/confi.git"
"url": "https://github.com/firstandthird/confi.git"
},

@@ -14,3 +14,5 @@ "dependencies": {

"cjson": "0.2.1",
"js-yaml": "~2.0.5"
"glob": "^5.0.3",
"js-yaml": "~2.0.5",
"mustache": "^1.1.0"
},

@@ -17,0 +19,0 @@ "devDependencies": {

@@ -14,2 +14,3 @@ var confi = require('../');

exports.testDev = function(t) {
process.env.testEnv = 'test';
confi.reset();

@@ -21,2 +22,5 @@ var config = confi.load();

t.equal(config.analytics.profile, 'ga-xxx');
t.equal(config.isTest, true);
t.equal(config.testHost, 'localhost/test/path');
t.equal(config.ENV.testEnv, 'test');
t.equal(config.env, 'dev');

@@ -41,3 +45,3 @@ t.done();

env: 'dev',
userConfig: true
userConfig: true
});

@@ -44,0 +48,0 @@ t.equal(config.analytics.enabled, true);

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