+ mergePathData(obj, path, data) {
+ path = path.split(/[\.\[\]]/).filter(d => d);
+ // enable look-ahead to determine if type is array or object
+ const pathCopy = path.slice();
+ let resolvedObj = obj;
+ if (path.length) {
+ // last item in path used to assign value on the resolved object
+ const name = path.pop();
+ resolvedObj = path.reduce((r, p, i) => {
+ if (typeof (r[p]) !== 'object') {
+ // look-ahead to see if next path item is a number
+ const isArray = !isNaN(parseInt(pathCopy[i + 1], 10));
+ r[p] = isArray ? [] : {}
+ }
+ return r[p];
+ }, obj)[name];
+ }
+ Object.assign(resolvedObj, data);
+ },