merge.js (1500B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var defaults = require( './defaults.js' ); 24 var mergefcn = require( './mergefcn.js' ); 25 26 27 // MAIN // 28 29 /** 30 * Merges objects into a target object. Note that the target object is mutated. 31 * 32 * @name merge 33 * @type {Function} 34 * @param {Object} target - target object 35 * @param {...Object} source - source objects (i.e., objects to be merged into the target object) 36 * @throws {Error} must provide a target object and one or more source objects 37 * @throws {TypeError} first argument must be an object 38 * @throws {TypeError} source arguments must be objects 39 * @returns {Object} merged (target) object 40 * 41 * @example 42 * var target = { 43 * 'a': 'beep' 44 * }; 45 * var source = { 46 * 'a': 'boop', 47 * 'b': 'bap' 48 * }; 49 * 50 * var out = merge( target, source ); 51 * // returns {'a':'boop', 'b':'bap'} 52 */ 53 var merge = mergefcn( defaults ); 54 55 56 // EXPORTS // 57 58 module.exports = merge;