| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | var baseMerge = require('./_baseMerge'), |
| 2 | isObject = require('./isObject'); |
| 3 | |
| 4 | /** |
| 5 | * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source |
| 6 | * objects into destination objects that are passed thru. |
| 7 | * |
| 8 | * @private |
| 9 | * @param {*} objValue The destination value. |
| 10 | * @param {*} srcValue The source value. |
| 11 | * @param {string} key The key of the property to merge. |
| 12 | * @param {Object} object The parent object of `objValue`. |
| 13 | * @param {Object} source The parent object of `srcValue`. |
| 14 | * @param {Object} [stack] Tracks traversed source values and their merged |
| 15 | * counterparts. |
| 16 | * @returns {*} Returns the value to assign. |
| 17 | */ |
| 18 | function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { |
| 19 | if (isObject(objValue) && isObject(srcValue)) { |
| 20 | // Recursively merge objects and arrays (susceptible to call stack limits). |
| 21 | stack.set(srcValue, objValue); |
| 22 | baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack); |
| 23 | stack['delete'](srcValue); |
| 24 | } |
| 25 | return objValue; |
| 26 | } |
| 27 | |
| 28 | module.exports = customDefaultsMerge; |