Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
nested-config
Advanced tools
Readme
Configuration object wrapper for nested configs.
Features:
Create new config object using create(overrides [object], defaults [object]).
const nc = require('nested-config');
let config = nc.create({a: 'new value'}, {a: 'default value'});
Now config
is itself a configuration object. All your current settings are stored in it.
It keeps track of default options for you as well. The object has the following API.
config.a; // 'new value'
config.getDefault('a'); // 'default value'
config.add({b: 1}, {b: 0}); // overrides, defaults
config.b; // 1
config.getDefault('b'); // 0
const nc = require('nested-config');
let defaults = {
yourOption: 1,
nested: {
option: "two",
array: [1]
}
};
let config = nc.create({yourOption: 2}, defaults);
config.yourOption; // 2
config.nested.array; // [1] (default)
let overrides = {
yourOption: 3,
nested: {
option: "three",
array: [2]
},
};
config.add(overrides, {}); // performs deep merge into current config state, leaves defaults unchanged
config.nested.array; // [2]
config.yourOption; // 3
config.getDefault('yourOption'); // 1
config.nested.option; // "three"
config.getPropRef('nested.option'); // "three" (same as above)
config.getDefault('nested.option'); // "two"
By default, arrays are replaced. For concatenation, pass additional option {arrayBehavior: 1}
to add
.
For more detail and other options, see API docs.
config.add({nested: {array: [3]}}, {}, { arrayBehavior: 1 });
config.nested.array; // [2, 3]
Prepare nconf
wrapper:
const nconf = require('nconf');
const nc = require('./config');
let defaultConfig = nc.create({}, {some: "config"});
nconf
.env()
.argv()
.defaults(defaultConfig);
// exports your current config
module.exports.nconf = nconf;
// manipulate default config (e.g. add new options for embedded modules)
module.exports.defaults = defaultConfig;
The module exports two useful functions which it uses internally: mergeDeep()
and plainify()
.
See API docs for more information.
const nc = require('nested-config');
let obj1 = {
a: 1,
nested: {
arr: [1, 2]
}
};
let obj2 = {
a: 2,
nested: {
arr: [3],
foo: 'bar'
}
};
nc.mergeDeep(obj1, obj2, {arrayBehavior: 1});
/* obj1:
{
a: 2,
nested: {
arr: [1, 2, 3],
foo: 'bar'
}
}
*/
let obj3 = nc.plainify(obj2);
/* obj3:
{
a: 2,
'nested.arr': [3],
'nested.foo': 'bar'
}
*/
API docs are available on the wiki.
FAQs
Manage and merge nested configuration objects, keeping track of your defaults
The npm package nested-config receives a total of 85 weekly downloads. As such, nested-config popularity was classified as not popular.
We found that nested-config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.