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

fable-settings

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fable-settings - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

3

package.json
{
"name": "fable-settings",
"version": "1.0.2",
"version": "1.0.3",
"description": "A simple, tolerant configuration chain.",

@@ -32,4 +32,5 @@ "main": "source/Fable-Settings.js",

"dependencies": {
"match-all": "^1.2.5",
"underscore": "1.9.1"
}
}

@@ -10,3 +10,4 @@ /**

// Underscore for utility
var libUnderscore = require('underscore');
const libUnderscore = require('underscore');
const matchAll = require("match-all");

@@ -68,2 +69,34 @@ /**

// Resolve (recursive) any environment variables found in settings object.
var resolve_env = function(pSettings)
{
for(var k in pSettings)
{
if (typeof(pSettings[k]) === 'object')
{
resolve_env(pSettings[k]);
}
else if (typeof(pSettings[k]) === 'string')
{
if (pSettings[k].indexOf('${') >= 0)
{
//pick out and resolve env variables from the settings value.
var matches = matchAll(pSettings[k], /\$\{(.*?)\}/g).toArray();
matches.forEach((m)=>
{
//format: VAR_NAME|DEFAULT_VALUE
var parts = m.split('|');
var resolvedValue = process.env[parts[0]] || '';
if (!resolvedValue && parts.length>1)
{
resolvedValue = parts[1];
}
pSettings[k] = pSettings[k].replace('${' + m + '}', resolvedValue);
});
}
}
}
}
// Merge some new object into the existing settings.

@@ -74,2 +107,3 @@ var merge = function(pSettings)

_Settings = libUnderscore.extend((typeof(_Settings) === 'object') ? _Settings : {}, (typeof(pSettings) === 'object') ? pSettings : {});
resolve_env(_Settings);
return _Settings;

@@ -130,2 +164,3 @@ };

fill: fill,
resolve_env: resolve_env,

@@ -132,0 +167,0 @@ new: createNew

@@ -18,2 +18,4 @@ {

"Environment": "${NOT_DEFAULT|default}-${USE_DEFAULT|default}",
"MySQL":

@@ -20,0 +22,0 @@ {

@@ -170,2 +170,22 @@ /**

);
test
(
'resolve environment variables',
function()
{
process.env['NOT_DEFAULT'] = 'found_value';
var tmpFableSettings = require('../source/Fable-Settings.js').new(
{
DefaultConfigFile:__dirname+'/DefaultExampleSettings.json',
ConfigFile:__dirname+'/ExampleSettings.json'
});
Expect(tmpFableSettings).to.have.a.property('settings')
.that.is.a('object');
Expect(tmpFableSettings.settings).to.have.a.property('Environment')
.that.is.a('string');
Expect(tmpFableSettings.settings.Environment)
.to.equal('found_value-default');
}
);
}

@@ -172,0 +192,0 @@ );

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