Shallow copy two objects into a new object

Objects are merged from left to right. Thus, properties in objects further
to the right are preferred over those on the left.

@param {object} obj1
@param {object} obj2
@returns {object}
@api private
496993
function merge (obj1, obj2) {
  var c = {},
    keys = Object.keys(obj2),
    i;

  for (i = 0; i !== keys.length; i++) {
    c[keys[i]] = obj2[keys[i]];
  }

  keys = Object.keys(obj1);
  for (i = 0; i !== keys.length; i++) {
    if (!c.hasOwnProperty(keys[i])) {
      c[keys[i]] = obj1[keys[i]];
    }
  }

  return c;
}
653898
function haveDifferentKeys(object1, object2) {
  var keys1 = Object.keys(object1);
  var keys2 = Object.keys(object2);

  if (keys1.length !== keys2.length) {
    return true;
  }

  return !keys1.every(function existsInKeys2 (key) {
    return keys2.indexOf(key) !== -1;
  });
}
1223174
function (obj) {
        return _.cloneDeepWith(obj, function (value) {
            // falls back to default deepclone if object does not have explicit toJSON().
            if (value && _.isFunction(value.toJSON)) {
                return value.toJSON();
            }
        });
    }
110282
function diffObjects(value, oldValue) {
    if ( !(value && oldValue && typeof value === 'object' && typeof oldValue === 'object')) {
      throw new TypeError('Both values for diff.object must be objects');
    }
    var changeRecords = [];
    var prop, propOldValue, propValue;

    // Goes through the old object (should be a clone) and look for things that are now gone or changed
    for (prop in oldValue) {
      propOldValue = oldValue[prop];
      propValue = value[prop];

      // Allow for the case of obj.prop = undefined (which is a new property, even if it is undefined)
      if (propValue !== undefined && !diffBasic(propValue, propOldValue)) {
        continue;
      }

      // If the property is gone it was removed
      if (! (prop in value)) {
        changeRecords.push(new ChangeRecord(value, 'delete', prop, propOldValue));
      } else if (diffBasic(propValue, propOldValue)) {
        changeRecords.push(new ChangeRecord(value, 'update', prop, propOldValue));
      }
    }

    // Goes through the old object and looks for things that are new
    for (prop in value) {
      propValue = value[prop];
      if (! (prop in oldValue)) {
        changeRecords.push(new ChangeRecord(value, 'add', prop));
      }
    }

    if (Array.isArray(value) && value.length !== oldValue.length) {
      changeRecords.push(new ChangeRecord(value, 'update', 'length', oldValue.length));
    }

    return changeRecords;
  }
481799
def copy_object(self, obj, new_container, new_obj_name=None,
            content_type=None):
        
        return self.manager.copy_object(self, obj, new_container,
                new_obj_name=new_obj_name, content_type=content_type)
875329
function ( obj1, obj2 ) {
		var result;

		result = obj1.map( function ( i, idx ) {
			return [i, obj2[idx]];
		});

		return result;
	}
379255
function cloneIt2(o) {
	let keys = Object.keys(o);
	let current = o;
	const acc = {};
	let currentAcc = acc;

	let i = 0;
	let iMax = keys.length + 1;
	let previous = [];
	let activeKey = [];

	for (; i < iMax; i++) {
		if (i === iMax - 1) {
			if (!previous.length) {
				break;
			}

			const prev = previous.pop();
			activeKey.pop();

			i = prev.i;
			iMax = prev.iMax;
			keys = prev.keys;

			let j = 0;
			const jMax = activeKey.length;
			currentAcc = acc;
			current = o;

			for (; j < jMax; j++) {
				currentAcc = currentAcc[activeKey[j]];
				current = current[activeKey[j]];
			}
		} else if (typeof current[keys[i]] === 'object') {
			currentAcc[keys[i]] = {};

			previous.push({ i, iMax, keys });
			activeKey.push(keys[i]);
			current = current[keys[i]];
			currentAcc = currentAcc[keys[i]];
			i = -1;
			keys = Object.keys(current);
			iMax = keys.length + 1;
		} else {
			currentAcc[keys[i]] = current[keys[i]];
		}
	}

	return acc;
}
860843
function compareObjects(obj1, obj2) {
          var value, name;

          for (name in obj1) {
            // Obj1 has item obj2 doesn't have
            if (obj1.hasOwnProperty(name)) {
              value = obj2[name];

              // Obj2 doesn't have obj1 item
              if (typeof value == "undefined") {
                return false;
              }

              // Obj2 item has a different value
              if (obj1[name] != value) {
                return false;
              }

              // Delete similar value
              delete obj2[name];
            }
          }

          // Check if obj 2 has something obj 1 doesn't have
          for (name in obj2) {
            // Obj2 has item obj1 doesn't have
            if (obj2.hasOwnProperty(name)) {
              return false;
            }
          }

          return true;
        }
409093
private function _mergeRecursively($obj1, $obj2) {
        if(empty($obj1))
            return $obj2;

        if (is_object($obj2)) {
            $keys = array_keys(get_object_vars($obj2));

            foreach ($keys as $key) {
                if (
                    isset($obj1->{$key})
                    && is_object($obj1->{$key})
                    && is_object($obj2->{$key})
                ) {
                    $obj1->{$key} = $this->_mergeRecursively($obj1->{$key}, $obj2->{$key});
                } elseif (isset($obj1->{$key})
                    && is_array($obj1->{$key})
                    && is_array($obj2->{$key})
                ) {
                    $obj1->{$key} = $this->_mergeRecursively($obj1->{$key}, $obj2->{$key});
                }
                else if(!empty($obj2->{$key})) {
                        $obj1->{$key} = $obj2->{$key};
                }
            }

        } elseif (is_array($obj2)) {
            if ( is_array($obj1) && is_array($obj2) ) {
                foreach ($obj2 as $key => $value){
                    if (empty($obj1[$key])) {
                        $obj1[$key] = $obj2[$key];
                    }

                    if(!empty($obj2[$key])) {
                            $obj1[$key] = $this->mergeObjectsRecursively($obj1[$key], $obj2[$key]);
                    }
                }
            } else {
                $obj1 = $obj2;
            }
        }

        return $obj1;
    }
562966
function shallowClone(obj) {
    let result = {};
    for (let p in obj) {
        if (obj.hasOwnProperty(p)) {
            result[p] = obj[p];
        }
    }
    return result;
}
15064
function copy(target, obj) {
  if (isObject(obj)) {
    forIn(obj, function(value, key) {
      target[key] = value;
    });
  }
}
938136
function MergeRowsWithHeaders(obj1, obj2) {
  for(var p in obj2){
    if(obj1[p] instanceof Array && obj1[p] instanceof Array){
      obj1[p] = obj1[p].concat(obj2[p])
    } else {
      obj1[p] = obj2[p]
    }
  }
  return obj1;
}
1182170
function clone(obj) {
    if (typeof obj !== 'object') {
        return obj;
    }
    var ret;
    if (util.isArray(obj)) {
        ret = [];
        obj.forEach(function (val) {
            ret.push(clone(val));
        });
        return ret;
    }
    ret = {};
    Object.keys(obj).forEach(function (key) {
        ret[key] = clone(obj[key]);
    });
    return ret;
}
627754
function objMerge(a, b) {
	var obj = {};

	Object.keys(a).forEach(function (key) {
		obj[key] = a[key];
	});

	Object.keys(b).forEach(function (key) {
		obj[key] = b[key];
	});

	return obj;
}
1062732
function _copy_property(opts, key, a, b) {
	debug.assert(opts).is('object');
	debug.assert(key).is('string');
	debug.assert(a).is('object');
	debug.assert(b).is('object');

	a[key] = b[key];

	if(opts.cache && opts.cache._has_cursors && is.obj(b[key]) && b[key].hasOwnProperty('$id')) {
		var f = opts.cache.findCursor(b, key);
		if(f) {
			//debug.log('Expanding cursor...');
			opts.cache.addToCursor(f, a, key);
		}

	}
}
913985
function mergeObjects(source, target, opts) {
  const properties = Object.keys(source)

  for (let i = 0; i < properties.length; i++) {
    const property = properties[i]

    // Is this property on the list of exclusions?
    if (opts.exclusions.indexOf(property) !== -1) {
      continue
    }

    let item = source[property]

    // Is this an object? Should we perform recursive merge?
    if (opts.recurse && item instanceof Object) {
      // If the item on the source is object, we must have such object on the target as well
      // So we either reuse any such existing "receiving" object or we create a new one
      const receiver = target[property] instanceof Object ? target[property]
                                                          : new item.constructor()

      // "To understand recursion, you must first understand recursion."
      item = doMerge(item, receiver, opts)
    }

    target[property] = item
  }

  return target
}
788588
function mergeObject (a, b) {
  var keys = Object.keys(b)
  var k;

  for (var i = 0; i < keys.length; i++) {
    k = keys[i];

    if ('object' !== type(b[k]) && 'array' !== type(b[k])) {
      // TODO: better deref handling of other types
      a[k] = b[k];
    } else {
      a[k] = a.hasOwnProperty(k)
        ? merge(a[k], b[k])
        : merge('array' === type(b[k]) ? [] : {}, b[k]);
    }
  }

  return a;
}