@newdash/newdash
Version:
javascript/typescript utility library
50 lines (49 loc) • 1.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeWith = void 0;
const baseMerge_1 = __importDefault(require("./.internal/baseMerge"));
const createAssigner_1 = __importDefault(require("./.internal/createAssigner"));
/**
* @ignore
*/
const iMergeWith = (0, createAssigner_1.default)((object, source, srcIndex, customizer) => {
(0, baseMerge_1.default)(object, source, srcIndex, customizer);
});
/**
* This method is like `merge` except that it accepts `customizer` which
* is invoked to produce the merged values of the destination and source
* properties. If `customizer` returns `undefined`, merging is handled by the
* method instead. The `customizer` is invoked with six arguments:
* (objValue, srcValue, key, object, source, stack).
*
* **Note:** This method mutates `object`.
*
* @since 5.12.0
* @category Object
* @param object The destination object.
* @param sourcesOrCustomizer The source objects. The function to customize assigned values.
* @returns Returns `object`.
* @example
*
* ```js
* function customizer(objValue, srcValue) {
* if (Array.isArray(objValue)) {
* return objValue.concat(srcValue)
* }
* }
*
* const object = { 'a': [1], 'b': [2] }
* const other = { 'a': [3], 'b': [4] }
*
* mergeWith(object, other, customizer)
* // => { 'a': [1, 3], 'b': [2, 4] }
* ```
*/
function mergeWith(object, ...sourcesOrCustomizer) {
return iMergeWith(object, ...sourcesOrCustomizer);
}
exports.mergeWith = mergeWith;
exports.default = mergeWith;