Permalink
Browse files

fix: assign notation

  • Loading branch information...
adriancmiranda committed Jun 7, 2017
1 parent a861960 commit e6e225e691fec303d6177f47068cc33886ac3677
Showing with 7 additions and 4 deletions.
  1. +7 −4 source/assign.js
@@ -2,6 +2,7 @@ var isFn = require('./is/function');
var isObject = require('./is/object');

module.exports = function (strategy) {
var notation = '';
return function assign(target) {
var args = Array.prototype.slice.call(arguments);
var output = Object(target || {});
@@ -12,17 +13,19 @@ module.exports = function (strategy) {
var key = keys[iy];
var outputValue = output[key];
var sourceValue = from[key];
var notation = key;
if (Array.isArray(outputValue) || Array.isArray(sourceValue)) {
var f = Array.isArray(sourceValue) ? sourceValue.slice() : [];
var o = Array.isArray(outputValue) ? outputValue.slice() : [];
output[key] = strategy(f, o, notation, keys);
output[key] = strategy(f, o, notation + '.' + key, keys);
} else if (isFn(outputValue) || isFn(sourceValue)) {
output[key] = strategy(sourceValue, outputValue, notation, keys);
output[key] = strategy(sourceValue, outputValue, notation + '.' + key, keys);
} else if (isObject(outputValue) || isObject(sourceValue)) {
var cn = notation;
notation = `${cn ? cn + '.' : ''}${key}`;
output[key] = assign(outputValue, sourceValue);
notation = cn;
} else {
output[key] = strategy(sourceValue, outputValue, notation, keys);
output[key] = strategy(sourceValue, outputValue, notation + '.' + key, keys);
}
}
}

0 comments on commit e6e225e

Please sign in to comment.