Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

28 rader
1.0 KiB

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