mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Bump to v3.0.0.
This commit is contained in:
45
internal/baseMerge.js
Normal file
45
internal/baseMerge.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import arrayEach from './arrayEach';
|
||||
import baseForOwn from './baseForOwn';
|
||||
import baseMergeDeep from './baseMergeDeep';
|
||||
import isArray from '../lang/isArray';
|
||||
import isLength from './isLength';
|
||||
import isObjectLike from './isObjectLike';
|
||||
import isTypedArray from '../lang/isTypedArray';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.merge` without support for argument juggling,
|
||||
* multiple sources, and `this` binding `customizer` functions.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} source The source object.
|
||||
* @param {Function} [customizer] The function to customize merging properties.
|
||||
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
||||
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
||||
* @returns {Object} Returns the destination object.
|
||||
*/
|
||||
function baseMerge(object, source, customizer, stackA, stackB) {
|
||||
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
|
||||
|
||||
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
||||
if (isObjectLike(srcValue)) {
|
||||
stackA || (stackA = []);
|
||||
stackB || (stackB = []);
|
||||
return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
|
||||
}
|
||||
var value = object[key],
|
||||
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
||||
isCommon = typeof result == 'undefined';
|
||||
|
||||
if (isCommon) {
|
||||
result = srcValue;
|
||||
}
|
||||
if ((isSrcArr || typeof result != 'undefined') &&
|
||||
(isCommon || (result === result ? result !== value : value === value))) {
|
||||
object[key] = result;
|
||||
}
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
export default baseMerge;
|
||||
Reference in New Issue
Block a user