ricotta
Extend Source Objects According to a Given Field-map
Usage
Ricotta is useful for extending your hierarchical "config.json" file using ENV flat settings.
ricotta.extendByMapFactory(fieldMap)=>(sourceObj, extensionObj)=>sourceObj
Installation
This library is 100% ES5 compatible, no deps.
npm install ricotta
Example
var ricotta = ; // ricotta receives a field map, returns (sourceObj, extensionObj)=>sourceObj var extender = ; var env = processenv || "MY_ENV_KEY_1": "This is the value of key1" "MY_ENV_KEY_2_1": "This is the value of key2.key1" "MY_ENV_KEY_3": "This will be mapped only if the destination exists (yes)" "MY_ENV_KEY_4": "This will be mapped only if the destination exists (no)" ; var baseConfig = || "key1": "My setting" "key2": "key1": "My first nested setting" "key2": "My second nested setting" "key3": {} ; ; console; // { // key1: 'This is the value of key1', // key2: // { // key1: 'This is the value of key2.key1', // key2: 'My second nested setting', // key3: 'This will be mapped only if the destination exists (yes)' // } // }