deep_merge.js 663 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const deepmerge = require('deepmerge');
  3. const arrayMerge = (target, source, options) => {
  4. const destination = target.slice();
  5. source.forEach((item, index) => {
  6. if (typeof destination[index] === 'undefined') {
  7. destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
  8. } else if (options.isMergeableObject(item)) {
  9. destination[index] = deepmerge(target[index], item, options);
  10. } else if (!target.includes(item)) {
  11. destination.push(item);
  12. }
  13. });
  14. return destination;
  15. };
  16. function deepMerge(target, source) {
  17. return deepmerge(target, source, { arrayMerge });
  18. }
  19. module.exports = deepMerge;