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

fable-settings

Package Overview
Dependencies
Maintainers
3
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 2.0.3 to 2.0.4

2

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

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

@@ -110,2 +110,37 @@ /**

/**
* Check to see if a value is an object (but not an array).
*/
_isObject(value)
{
return typeof(value) === 'object' && !Array.isArray(value);
}
/**
* Merge two plain objects. Keys that are objects in both will be merged property-wise.
*/
_deepMergeObjects(toObject, fromObject)
{
if (!fromObject || !this._isObject(fromObject))
{
return;
}
Object.keys(fromObject).forEach((key) =>
{
const fromValue = fromObject[key];
if (this._isObject(fromValue))
{
const toValue = toObject[key];
if (toValue && this._isObject(toValue))
{
// both are objects, so do a recursive merge
this._deepMergeObjects(toValue, fromValue);
return;
}
}
toObject[key] = fromValue;
});
return toObject;
}
// Merge some new object into the existing settings.

@@ -121,3 +156,3 @@ merge(pSettingsFrom, pSettingsTo)

let tmpSettingsFromCopy = JSON.parse(JSON.stringify(tmpSettingsFrom));
tmpSettingsTo = Object.assign(tmpSettingsTo, tmpSettingsFromCopy);
tmpSettingsTo = this._deepMergeObjects(tmpSettingsTo, tmpSettingsFromCopy);

@@ -138,4 +173,7 @@ if (this._PerformEnvTemplating)

this.settings = Object.assign(tmpSettingsFrom, this.settings);
// do not mutate the From object property values
let tmpSettingsFromCopy = JSON.parse(JSON.stringify(tmpSettingsFrom));
this.settings = this._deepMergeObjects(tmpSettingsFromCopy, this.settings);
return this.settings;

@@ -142,0 +180,0 @@ }

@@ -5,3 +5,8 @@ {

"TestValue": "NOT_OVERIDDEN"
}
"TestValue": "NOT_OVERIDDEN",
"ComplexMerge":
{
"DefaultKey": "DefaultValue",
"OverriddenKey": "IrrelevantValue"
}
}

@@ -32,3 +32,8 @@ {

"LogStreams": [{"streamtype":"process.stdout", "level":"trace"}]
"LogStreams": [{"streamtype":"process.stdout", "level":"trace"}],
"ComplexMerge":
{
"NewKey": "NewValue",
"OverriddenKey": "ImportantValue"
}
}

@@ -97,3 +97,15 @@ /**

// Test the object fill method.
tmpFableSettings.fill({Product:'DontOverwriteMe',SomeFancySetting:'CreateMe'});
tmpFableSettings.fill({ ComplexMerge: { DefaultKey: 'DefaultValue' } });
const toFill =
{
Product:'DontOverwriteMe',
SomeFancySetting:'CreateMe',
ComplexMerge:
{
DefaultKey: 'IgnoredValue',
NewKey: 'NewValue',
},
};
const fillParameter = JSON.parse(JSON.stringify(toFill));
tmpFableSettings.fill(fillParameter);
// Fill should have ignored overwriting existing settings

@@ -107,3 +119,9 @@ Expect(tmpFableSettings.settings.Product)

tmpFableSettings.fill();
console.log('1')
Expect(tmpFableSettings.settings.ComplexMerge).to.deep.equal(
{
DefaultKey: 'DefaultValue',
NewKey: 'NewValue',
});
// ensure we didn't mutate the fill input
Expect(toFill).to.deep.equal(fillParameter);
}

@@ -123,2 +141,9 @@ );

.to.equal('BestProductEver - DEFAULT');
Expect(tmpFableSettings.settings).to.have.a.property('ComplexMerge')
.that.is.an('object');
Expect(tmpFableSettings.settings.ComplexMerge).to.deep.equal(
{
DefaultKey: 'DefaultValue',
OverriddenKey: 'IrrelevantValue',
});
}

@@ -158,2 +183,10 @@ );

.to.equal('NOT_OVERIDDEN');
Expect(tmpFableSettings.settings).to.have.a.property('ComplexMerge')
.that.is.an('object');
Expect(tmpFableSettings.settings.ComplexMerge).to.deep.equal(
{
DefaultKey: 'DefaultValue',
OverriddenKey: 'ImportantValue',
NewKey: 'NewValue',
});
}

@@ -197,2 +230,10 @@ );

.to.deep.equal(['found_value', 'default']);
Expect(tmpFableSettings.settings).to.have.a.property('ComplexMerge')
.that.is.an('object');
Expect(tmpFableSettings.settings.ComplexMerge).to.deep.equal(
{
DefaultKey: 'DefaultValue',
OverriddenKey: 'ImportantValue',
NewKey: 'NewValue',
});
}

@@ -223,2 +264,10 @@ );

.to.deep.equal(['${NOT_DEFAULT|default}', '${USE_DEFAULT|default}']);
Expect(tmpFableSettings.settings).to.have.a.property('ComplexMerge')
.that.is.an('object');
Expect(tmpFableSettings.settings.ComplexMerge).to.deep.equal(
{
DefaultKey: 'DefaultValue',
OverriddenKey: 'ImportantValue',
NewKey: 'NewValue',
});
}

@@ -225,0 +274,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