@rentpath/hive-config
v1.1.4
Published
Utilities for managing configuration objects in Node.js applications.
Downloads
1
Maintainers
Keywords
Readme
hive-config
Utilities for managing configuration objects in Node.js applications.
API Reference
merge(target, ...[sources])
Recursively merges own and inherited string keyed properties of source configuration objects into a destination object. Special handling is given to any property whose value is a function, and whose key beings with $
, which will be called as a resolver function with the previous value of the property as an argument. The return value is used as the merged property value.
const obj1 = {
foo: 'foo',
}
const obj2 = {
$foo: prev => `${prev} bar`
}
merge({}, obj1, obj2)
// -> { foo: 'foo bar' }
combine(target, ...[sources])
Recursively merges own and inherited string keyed properties of source configuration objects into a destination object, but with special handling for arrays. If both the source and the target are arrays, then the two arrays are combined.
const obj1 = {
items: [1],
}
const obj2 = {
items: [2],
}
combine({}, obj1, obj2)
// -> { items: [1, 2] }
compile(context, ...[configs])
A configuration resolver that iterates over a set of configs, and for each config that evaluates to a function, calls it with a provided context argument. The returned value(s) for each config are returned.
const config1 = {
foo: 'foo',
}
const config2 = ctx => ({
foo: ctx.foo,
})
compile({ foo: 'bar' }, config1, config2)
// -> [{ foo: 'foo' }, { foo: 'bar' }]