@@ -72,18 +72,21 @@ function cloneOptionObject(obj) {
72
72
}
73
73
74
74
/**
75
- * @param merged already cloned
76
- * @return cloned Object
75
+ * @param {* } merged already cloned
76
+ * @param {* } source something to merge
77
+ * @param {string[] } keys keys to merge
78
+ * @param {Object } config Config Object
79
+ * @returns {* } cloned Object
77
80
*/
78
- const mergeKeys = ( merged , source , keys , mergeOpts ) => {
81
+ const mergeKeys = ( merged , source , keys , config ) => {
79
82
keys . forEach ( key => {
80
- if ( typeof source [ key ] === 'undefined' && mergeOpts . ignoreUndefined ) {
83
+ if ( typeof source [ key ] === 'undefined' && config . ignoreUndefined ) {
81
84
return ;
82
85
}
83
86
84
87
// Do not recurse into prototype chain of merged
85
88
if ( key in merged && merged [ key ] !== Object . getPrototypeOf ( merged ) ) {
86
- defineProperty ( merged , key , merge ( merged [ key ] , source [ key ] , mergeOpts ) ) ;
89
+ defineProperty ( merged , key , merge ( merged [ key ] , source [ key ] , config ) ) ;
87
90
} else {
88
91
defineProperty ( merged , key , clone ( source [ key ] ) ) ;
89
92
}
@@ -93,12 +96,14 @@ const mergeKeys = (merged, source, keys, mergeOpts) => {
93
96
} ;
94
97
95
98
/**
96
- * @param merged already cloned
97
- * @return cloned Object
99
+ * @param {* } merged already cloned
100
+ * @param {* } source something to merge
101
+ * @param {Object } config Config Object
102
+ * @returns {* } cloned Object
98
103
*
99
104
* see [Array.prototype.concat ( ...arguments )](http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.concat)
100
105
*/
101
- const concatArrays = ( merged , source , mergeOpts ) => {
106
+ const concatArrays = ( merged , source , config ) => {
102
107
let result = merged . slice ( 0 , 0 ) ;
103
108
let resultIndex = 0 ;
104
109
@@ -124,31 +129,33 @@ const concatArrays = (merged, source, mergeOpts) => {
124
129
// Merge non-index keys
125
130
result = mergeKeys ( result , array , getEnumerableOwnPropertyKeys ( array ) . filter ( key => {
126
131
return indices . indexOf ( key ) === - 1 ;
127
- } ) , mergeOpts ) ;
132
+ } ) , config ) ;
128
133
} ) ;
129
134
130
135
return result ;
131
136
} ;
132
137
133
138
/**
134
- * @param merged already cloned
135
- * @return cloned Object
139
+ * @param {* } merged already cloned
140
+ * @param {* } source something to merge
141
+ * @param {Object } config Config Object
142
+ * @returns {* } cloned Object
136
143
*/
137
- function merge ( merged , source , mergeOpts ) {
138
- if ( mergeOpts . concatArrays && Array . isArray ( merged ) && Array . isArray ( source ) ) {
139
- return concatArrays ( merged , source , mergeOpts ) ;
144
+ function merge ( merged , source , config ) {
145
+ if ( config . concatArrays && Array . isArray ( merged ) && Array . isArray ( source ) ) {
146
+ return concatArrays ( merged , source , config ) ;
140
147
}
141
148
142
149
if ( ! isOptionObject ( source ) || ! isOptionObject ( merged ) ) {
143
150
return clone ( source ) ;
144
151
}
145
152
146
- return mergeKeys ( merged , source , getEnumerableOwnPropertyKeys ( source ) , mergeOpts ) ;
153
+ return mergeKeys ( merged , source , getEnumerableOwnPropertyKeys ( source ) , config ) ;
147
154
}
148
155
149
156
module . exports = function ( ...options ) {
150
- const mergeOpts = merge ( clone ( defaultMergeOpts ) , ( this !== globalThis && this ) || { } , defaultMergeOpts ) ;
151
- let merged = { foobar : { } } ;
157
+ const config = merge ( clone ( defaultMergeOpts ) , ( this !== globalThis && this ) || { } , defaultMergeOpts ) ;
158
+ let merged = { _ : { } } ;
152
159
153
160
for ( const option of options ) {
154
161
if ( option === undefined ) {
@@ -159,8 +166,8 @@ module.exports = function (...options) {
159
166
throw new TypeError ( '`' + option + '` is not an Option Object' ) ;
160
167
}
161
168
162
- merged = merge ( merged , { foobar : option } , mergeOpts ) ;
169
+ merged = merge ( merged , { _ : option } , config ) ;
163
170
}
164
171
165
- return merged . foobar ;
172
+ return merged . _ ;
166
173
} ;
0 commit comments