MCPcopy
hub / github.com/di-sukharev/opencommit / merge2

Function merge2

out/cli.cjs:27943–27990  ·  view source on GitHub ↗
(target, source, options)

Source from the content-addressed store, hash-verified

27941 return obj;
27942 };
27943 var merge2 = function merge3(target, source, options) {
27944 if (!source) {
27945 return target;
27946 }
27947 if (typeof source !== "object") {
27948 if (isArray2(target)) {
27949 target.push(source);
27950 } else if (target && typeof target === "object") {
27951 if (options && (options.plainObjects || options.allowPrototypes) || !has.call(Object.prototype, source)) {
27952 target[source] = true;
27953 }
27954 } else {
27955 return [target, source];
27956 }
27957 return target;
27958 }
27959 if (!target || typeof target !== "object") {
27960 return [target].concat(source);
27961 }
27962 var mergeTarget = target;
27963 if (isArray2(target) && !isArray2(source)) {
27964 mergeTarget = arrayToObject2(target, options);
27965 }
27966 if (isArray2(target) && isArray2(source)) {
27967 source.forEach(function(item, i3) {
27968 if (has.call(target, i3)) {
27969 var targetItem = target[i3];
27970 if (targetItem && typeof targetItem === "object" && item && typeof item === "object") {
27971 target[i3] = merge3(targetItem, item, options);
27972 } else {
27973 target.push(item);
27974 }
27975 } else {
27976 target[i3] = item;
27977 }
27978 });
27979 return target;
27980 }
27981 return Object.keys(source).reduce(function(acc, key) {
27982 var value = source[key];
27983 if (has.call(acc, key)) {
27984 acc[key] = merge3(acc[key], value, options);
27985 } else {
27986 acc[key] = value;
27987 }
27988 return acc;
27989 }, mergeTarget);
27990 };
27991 var assign = function assignSingleSource(target, source) {
27992 return Object.keys(source).reduce(function(acc, key) {
27993 acc[key] = source[key];

Callers 1

mergeConfigFunction · 0.85

Calls 6

isArray2Function · 0.85
arrayToObject2Function · 0.85
concatMethod · 0.80
pushMethod · 0.45
forEachMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…