📄 deepMerge¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/utils/src/eslint-utils/deepMerge.ts
Functions¶
isObjectNotArray(obj: unknown): obj is ObjectLike¶
Check if the variable contains an object strictly rejecting arrays
Returns: undefined
true if obj is an object
Raw JSDoc
Calls:
Array.isArray
Code
deepMerge(first: ObjectLike, second: ObjectLike): Record<string, unknown>¶
Pure function - doesn't mutate either parameter! Merges two objects together deeply, overwriting the properties in first with the properties in second
Parameters:
firstany: The first objectsecondany: The second object
Returns: undefined
a new object
Raw JSDoc
Calls:
Object.keysObject.fromEntries[...keys].mapisObjectNotArraydeepMerge
Internal Comments:
Code
export function deepMerge(
first: ObjectLike = {},
second: ObjectLike = {},
): Record<string, unknown> {
// get the unique set of keys across both objects
const keys = new Set([...Object.keys(first), ...Object.keys(second)]);
return Object.fromEntries(
[...keys].map(key => {
const firstHasKey = key in first;
const secondHasKey = key in second;
const firstValue = first[key];
const secondValue = second[key];
let value;
if (firstHasKey && secondHasKey) {
if (isObjectNotArray(firstValue) && isObjectNotArray(secondValue)) {
// object type
value = deepMerge(firstValue, secondValue);
} else {
// value type
value = secondValue;
}
} else if (firstHasKey) {
value = firstValue;
} else {
value = secondValue;
}
return [key, value];
}),
);
}
Type Aliases¶
ObjectLike<T = unknown>¶
Generated by Syntax Scribe