1.1.4 • Published 5 years ago

@rentpath/hive-config v1.1.4

Weekly downloads
4
License
MIT
Repository
-
Last release
5 years ago

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' }]
1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago