| 258 | ): T & S1 & S2 & S3 & S4; |
| 259 | export function merge<T>(target: T, source: AnyObject[], options?: MergeOptions): AnyObject; |
| 260 | export function merge<T>(target: T, source: AnyObject[], options?: MergeOptions): AnyObject { |
| 261 | const sources = isArray(source) ? source : [source]; |
| 262 | const ilen = sources.length; |
| 263 | |
| 264 | if (!isObject(target)) { |
| 265 | return target as AnyObject; |
| 266 | } |
| 267 | |
| 268 | options = options || {}; |
| 269 | const merger = options.merger || _merger; |
| 270 | let current: AnyObject; |
| 271 | |
| 272 | for (let i = 0; i < ilen; ++i) { |
| 273 | current = sources[i]; |
| 274 | if (!isObject(current)) { |
| 275 | continue; |
| 276 | } |
| 277 | |
| 278 | const keys = Object.keys(current); |
| 279 | for (let k = 0, klen = keys.length; k < klen; ++k) { |
| 280 | merger(keys[k], target, current, options as AnyObject); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | return target; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Recursively deep copies `source` properties into `target` *only* if not defined in target. |