massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @humanwhocodes / object-schema / src / merge-strategy.js
1 /**
2  * @filedescription Merge Strategy
3  */
4
5 "use strict";
6
7 //-----------------------------------------------------------------------------
8 // Class
9 //-----------------------------------------------------------------------------
10
11 /**
12  * Container class for several different merge strategies.
13  */
14 class MergeStrategy {
15
16     /**
17      * Merges two keys by overwriting the first with the second.
18      * @param {*} value1 The value from the first object key. 
19      * @param {*} value2 The value from the second object key.
20      * @returns {*} The second value.
21      */
22     static overwrite(value1, value2) {
23         return value2;
24     }
25
26     /**
27      * Merges two keys by replacing the first with the second only if the
28      * second is defined.
29      * @param {*} value1 The value from the first object key. 
30      * @param {*} value2 The value from the second object key.
31      * @returns {*} The second value if it is defined.
32      */
33     static replace(value1, value2) {
34         if (typeof value2 !== "undefined") {
35             return value2;
36         }
37
38         return value1;
39     }
40
41     /**
42      * Merges two properties by assigning properties from the second to the first.
43      * @param {*} value1 The value from the first object key.
44      * @param {*} value2 The value from the second object key.
45      * @returns {*} A new object containing properties from both value1 and
46      *      value2.
47      */
48     static assign(value1, value2) {
49         return Object.assign({}, value1, value2);
50     }
51 }
52
53 exports.MergeStrategy = MergeStrategy;