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
tang-0.2.1 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_merge.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@rails/webpacker/package/utils/deep_merge.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@rails/webpacker/package/utils/deep_merge.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@rails/webpacker/package/utils/deep_merge.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@rails/webpacker/package/utils/deep_merge.js
jetpacker-0.5.0 package/utils/deep_merge.js
tang-0.2.0 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_merge.js
tang-0.1.0 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_merge.js
tang-0.0.9 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_merge.js
webpacker-5.2.1 package/utils/deep_merge.js
webpacker-4.3.0 package/utils/deep_merge.js
webpacker-5.2.0 package/utils/deep_merge.js
enju_library-0.3.8 spec/dummy/node_modules/@rails/webpacker/package/utils/deep_merge.js
webpacker-5.1.1 package/utils/deep_merge.js
webpacker-5.1.0 package/utils/deep_merge.js
webpacker-5.0.1 package/utils/deep_merge.js
webpacker-5.0.0 package/utils/deep_merge.js
jetpacker-0.4.2 package/utils/deep_merge.js
jetpacker-0.4.1 package/utils/deep_merge.js
jetpacker-0.4.0 package/utils/deep_merge.js