.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / experimental-utils / dist / eslint-utils / deepMerge.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.isObjectNotArray = exports.deepMerge = void 0;
4 /**
5  * Check if the variable contains an object strictly rejecting arrays
6  * @param obj an object
7  * @returns `true` if obj is an object
8  */
9 function isObjectNotArray(obj) {
10     return typeof obj === 'object' && !Array.isArray(obj);
11 }
12 exports.isObjectNotArray = isObjectNotArray;
13 /**
14  * Pure function - doesn't mutate either parameter!
15  * Merges two objects together deeply, overwriting the properties in first with the properties in second
16  * @param first The first object
17  * @param second The second object
18  * @returns a new object
19  */
20 function deepMerge(first = {}, second = {}) {
21     // get the unique set of keys across both objects
22     const keys = new Set(Object.keys(first).concat(Object.keys(second)));
23     return Array.from(keys).reduce((acc, key) => {
24         const firstHasKey = key in first;
25         const secondHasKey = key in second;
26         const firstValue = first[key];
27         const secondValue = second[key];
28         if (firstHasKey && secondHasKey) {
29             if (isObjectNotArray(firstValue) && isObjectNotArray(secondValue)) {
30                 // object type
31                 acc[key] = deepMerge(firstValue, secondValue);
32             }
33             else {
34                 // value type
35                 acc[key] = secondValue;
36             }
37         }
38         else if (firstHasKey) {
39             acc[key] = firstValue;
40         }
41         else {
42             acc[key] = secondValue;
43         }
44         return acc;
45     }, {});
46 }
47 exports.deepMerge = deepMerge;
48 //# sourceMappingURL=deepMerge.js.map