mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Bump to v4.1.0.
This commit is contained in:
44
_baseMerge.js
Normal file
44
_baseMerge.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import Stack from './_Stack';
|
||||
import arrayEach from './_arrayEach';
|
||||
import assignMergeValue from './_assignMergeValue';
|
||||
import baseMergeDeep from './_baseMergeDeep';
|
||||
import isArray from './isArray';
|
||||
import isObject from './isObject';
|
||||
import isTypedArray from './isTypedArray';
|
||||
import keysIn from './keysIn';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.merge` without support for multiple sources.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} source The source object.
|
||||
* @param {number} srcIndex The index of `source`.
|
||||
* @param {Function} [customizer] The function to customize merged values.
|
||||
* @param {Object} [stack] Tracks traversed source values and their merged counterparts.
|
||||
*/
|
||||
function baseMerge(object, source, srcIndex, customizer, stack) {
|
||||
if (object === source) {
|
||||
return;
|
||||
}
|
||||
var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn(source);
|
||||
arrayEach(props || source, function(srcValue, key) {
|
||||
if (props) {
|
||||
key = srcValue;
|
||||
srcValue = source[key];
|
||||
}
|
||||
if (isObject(srcValue)) {
|
||||
stack || (stack = new Stack);
|
||||
baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
||||
}
|
||||
else {
|
||||
var newValue = customizer ? customizer(object[key], srcValue, (key + ''), object, source, stack) : undefined;
|
||||
if (newValue === undefined) {
|
||||
newValue = srcValue;
|
||||
}
|
||||
assignMergeValue(object, key, newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default baseMerge;
|
||||
Reference in New Issue
Block a user