Sha256: 791efa6c65e11a64d286415b1b0ea46dec48c9a619e2090ce53a093f54d3e6a5

Contents?: true

Size: 740 Bytes

Versions: 26

Compression:

Stored size: 740 Bytes

Contents

import { isObject } from './isObject'

/**
 * Deeply merges two given objects with the right one
 * having a priority during property assignment.
 */
export function mergeRight(
  left: Record<string, any>,
  right: Record<string, any>,
) {
  return Object.entries(right).reduce(
    (result, [key, rightValue]) => {
      const leftValue = result[key]

      if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
        result[key] = leftValue.concat(rightValue)
        return result
      }

      if (isObject(leftValue) && isObject(rightValue)) {
        result[key] = mergeRight(leftValue, rightValue)
        return result
      }

      result[key] = rightValue
      return result
    },
    Object.assign({}, left),
  )
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/msw/src/core/utils/internal/mergeRight.ts