Sha256: 4c0cf821c0a53fa3fbe6279928428338a8ae515e9f2c93134317cedd3fd32a7d

Contents?: true

Size: 608 Bytes

Versions: 28

Compression:

Stored size: 608 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) => (Object.assign(
      {},
      result,
      { [key]: deepMerge(target[key], source[key]) }
    )),
    {}
  )
}

module.exports = deepMerge

Version data entries

28 entries across 28 versions & 5 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/@rails/webpacker/package/utils/deep_merge.js
disco_app-0.18.2 test/dummy/node_modules/@rails/webpacker/package/utils/deep_merge.js
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/utils/deep_merge.js
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/utils/deep_merge.js
jester-data-8.0.0 node_modules/@rails/webpacker/package/utils/deep_merge.js
ezii-os-5.2.1 node_modules/@rails/webpacker/package/utils/deep_merge.js
ezii-os-2.0.1 node_modules/@rails/webpacker/package/utils/deep_merge.js
ezii-os-1.1.0 node_modules/@rails/webpacker/package/utils/deep_merge.js
ezii-os-1.0.0 node_modules/@rails/webpacker/package/utils/deep_merge.js
ezii-os-0.0.0.1.0 node_modules/@rails/webpacker/package/utils/deep_merge.js
ezii-os-0.0.0.0.1 node_modules/@rails/webpacker/package/utils/deep_merge.js
webpacker-4.0.7 package/utils/deep_merge.js
webpacker-4.0.6 package/utils/deep_merge.js
webpacker-4.0.5 package/utils/deep_merge.js
webpacker-4.0.4 package/utils/deep_merge.js
webpacker-4.0.3 package/utils/deep_merge.js
webpacker-4.0.2 package/utils/deep_merge.js
webpacker-4.0.1 package/utils/deep_merge.js
webpacker-4.0.0 package/utils/deep_merge.js
webpacker-4.0.0.rc.8 package/utils/deep_merge.js