MCPcopy
hub / github.com/jestjs/jest / deepMergeArray

Function deepMergeArray

packages/jest-snapshot/src/utils.ts:91–108  ·  view source on GitHub ↗
(target: Array<any>, source: Array<any>)

Source from the content-addressed store, hash-verified

89 ['Any', 'Anything'].includes(input.constructor.name);
90
91const deepMergeArray = (target: Array<any>, source: Array<any>) => {
92 const mergedOutput = [...target];
93
94 for (const [index, sourceElement] of source.entries()) {
95 const targetElement = mergedOutput[index];
96
97 if (Array.isArray(target[index]) && Array.isArray(sourceElement)) {
98 mergedOutput[index] = deepMergeArray(target[index], sourceElement);
99 } else if (isObject(targetElement) && !isAnyOrAnything(sourceElement)) {
100 mergedOutput[index] = deepMerge(target[index], sourceElement);
101 } else {
102 // Source does not exist in target or target is primitive and cannot be deep merged
103 mergedOutput[index] = sourceElement;
104 }
105 }
106
107 return mergedOutput;
108};
109
110// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
111export const deepMerge = (target: any, source: any): any => {

Callers 1

deepMergeFunction · 0.85

Calls 3

isAnyOrAnythingFunction · 0.85
deepMergeFunction · 0.85
isObjectFunction · 0.70

Tested by

no test coverage detected