Sha256: 5d659496f93d4f86467a835af3933fd49d512b98c7c9aaf59adb1e7253455d54

Contents?: true

Size: 585 Bytes

Versions: 46

Compression:

Stored size: 585 Bytes

Contents

const {
  isObject, isArray, isEqual, isEmpty
} = require('./helpers')

const deepMerge = (target, source) => {
  if (isEmpty(target)) return source
  if (isEmpty(source)) return target
  if (isEqual(target, source)) return source
  if (isArray(target) && isArray(source)) return [...new Set([...target, ...source])]
  if (!(isObject(target) && isObject(source))) return source

  return [...Object.keys(target), ...Object.keys(source)].reduce(
    (result, key) => ({

      ...result,
      [key]: deepMerge(target[key], source[key])
    }),
    {}
  )
}

module.exports = deepMerge

Version data entries

46 entries across 45 versions & 9 rubygems

Version Path
jetpacker-0.3.0 package/utils/deep_merge.js
jetpacker-0.2.0 package/utils/deep_merge.js
webpacker-4.2.2 package/utils/deep_merge.js
webpacker-4.2.1 package/utils/deep_merge.js
webpacker-4.2.0 package/utils/deep_merge.js
webpacker-4.1.0 package/utils/deep_merge.js