@qiwi/uniconfig-plugin-datatree
Advanced tools
Comparing version 2.15.1 to 2.16.0
@@ -0,1 +1,8 @@ | ||
# [@qiwi/uniconfig-plugin-datatree-v2.16.0](https://github.com/qiwi/uniconfig/compare/v2.15.1...v2.16.0) (2018-11-15) | ||
### Features | ||
* **datatree:** support any regular and dot separated keys conjunction ([472932f](https://github.com/qiwi/uniconfig/commit/472932f)) | ||
# [@qiwi/uniconfig-plugin-datatree-v2.15.1](https://github.com/qiwi/uniconfig/compare/v2.15.0...v2.15.1) (2018-11-15) | ||
@@ -2,0 +9,0 @@ |
@@ -29,2 +29,16 @@ "use strict"; | ||
var compact = function compact(object) { | ||
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.'; | ||
var paths = {}; | ||
var process = function process(branch, path) { | ||
(0, _lodashEs.isObject)(branch) && (0, _lodashEs.keys)(branch).length > 0 || (0, _lodashEs.isArray)(branch) ? (0, _lodashEs.forEach)(branch, function (value, name) { | ||
process(value, path + separator + name); | ||
}) : paths[path] = branch; | ||
}; | ||
(0, _lodashEs.forEach)(object, process); | ||
return paths; | ||
}; | ||
var evaluate = function evaluate(data, sources) { | ||
@@ -42,3 +56,3 @@ return (0, _lodashEs.reduce)(data, function (result, value, key) { | ||
if (source) { | ||
result[key] = path ? source[path] || (0, _lodashEs.get)(source, path) : source; | ||
result[key] = path ? source[path] || (0, _lodashEs.get)(source, path) || (0, _lodashEs.get)(compact(source), path) : source; | ||
} else {} | ||
@@ -45,0 +59,0 @@ |
@@ -11,3 +11,3 @@ // | ||
import { get, map, reduce, mapValues } from 'lodash-es' | ||
import { get, map, reduce, mapValues, forEach, keys, isArray, isObject } from 'lodash-es' | ||
import { pipeExecutor, SYNC, ASYNC } from '@qiwi/uniconfig-core' | ||
@@ -32,2 +32,16 @@ | ||
const compact = (object , separator ='.') => { | ||
const paths = {} | ||
const process = (branch, path) => { | ||
isObject(branch) && keys(branch).length > 0 || isArray(branch) ? | ||
forEach(branch, (value, name) => { | ||
process(value, path + separator + name); | ||
}) : | ||
(paths[path] = branch); | ||
} | ||
forEach(object, process) | ||
return paths; | ||
} | ||
export const evaluate = (data , sources ) => reduce( | ||
@@ -43,3 +57,3 @@ data, | ||
result[key] = path | ||
? source[path] || get(source, path) | ||
? source[path] || get(source, path) || get(compact(source), path) | ||
: source | ||
@@ -46,0 +60,0 @@ } else { |
{ | ||
"name": "@qiwi/uniconfig-plugin-datatree", | ||
"version": "2.15.1", | ||
"version": "2.16.0", | ||
"description": "uniconfig datatree plugin", | ||
@@ -5,0 +5,0 @@ "main": "dist/es6/index.js", |
@@ -23,3 +23,4 @@ # @qiwi/uniconfig-plugin-datatree | ||
otherParam: '$a:b', | ||
anotherParam: '$a:d.e.f.g' | ||
anotherParam: '$a:d.e.f.g', | ||
lastParam: '$a:i.j.k.l.m.n' | ||
}, | ||
@@ -35,3 +36,8 @@ source: { | ||
b: 'c', | ||
'd.e.f.g': 'h' | ||
'd.e.f.g': 'h', | ||
'i.j': { | ||
k: { | ||
'l.m.n': 'o' | ||
} | ||
} | ||
} | ||
@@ -48,2 +54,3 @@ } | ||
config.get('anotherParam') // 'h' | ||
config.get('lastParam') // 'o' | ||
``` |
12407
188
54