Skip to content

Commit

Permalink
fix: assign notation
Browse files Browse the repository at this point in the history
  • Loading branch information
adriancmiranda committed Jun 7, 2017
1 parent a861960 commit e6e225e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions source/assign.js
Expand Up @@ -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 || {});
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit e6e225e

Please sign in to comment.