/*
Clones an object and its prototype while maintaining enumerable
keys and support for `instanceof`.
 TODO :: this may not be necessary if linkObj.base.parsed and linkObj.url.parsed are cleaned out TODO :: move this into urlobj
963467
function cloneObject(source)
{
	var clone,key,value;
	
	if (Array.isArray(source) === true)
	{
		clone = [];
	}
	else
	{
		// Only clone the prototype -- more efficient as it will not convert keys to prototype keys
		clone = Object.create( Object.getPrototypeOf(source) );
	}
	
	// Clone keys/indexes
	// TODO :: use Object.keys() for more speed
	for (key in source)
	{
		if (hasOwnProperty.call(source, key) === true)
		{
			value = source[key];
			
			if (value!==null && typeof value==="object")
			{
				clone[key] = cloneObject(value);
			}
			else
			{
				clone[key] = value;
			}
		}
	}
	
	return clone;
}
1358969
function clone (obj, deep) {
  if (obj) {
    return deep ? deepClone(obj) : objectAssign(isPlainObject(obj) ? {} : [], obj)
  }
  return obj
}
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;
}
104642
function(o) {
        var type = _.util.type(o);

        switch (type) {
          case 'Object':
            var clone = {};

            for (var key in o) {
              if (o.hasOwnProperty(key)) {
                clone[key] = _.util.clone(o[key]);
              }
            }

            return clone;

          case 'Array':
            return o.slice();
        }

        return o;
      }
481523
function() {
      // inherit instance attributes
      var clonable = this.prototype._instanceAttributes;
      // merge attributes from element
      var a$ = this.attributes;
      for (var i=0, l=a$.length, a; (i<l) && (a=a$[i]); i++) {  
        if (this.isInstanceAttribute(a.name)) {
          clonable[a.name] = a.value;
        }
      }
    }
988606
function (o, visited) {
			var type = _.util.type(o);
			visited = visited || {};

			switch (type) {
				case 'Object':
					if (visited[_.util.objId(o)]) {
						return visited[_.util.objId(o)];
					}
					var clone = {};
					visited[_.util.objId(o)] = clone;

					for (var key in o) {
						if (o.hasOwnProperty(key)) {
							clone[key] = _.util.clone(o[key], visited);
						}
					}

					return clone;

				case 'Array':
					if (visited[_.util.objId(o)]) {
						return visited[_.util.objId(o)];
					}
					var clone = [];
					visited[_.util.objId(o)] = clone;

					o.forEach(function (v, i) {
						clone[i] = _.util.clone(v, visited);
					});

					return clone;
			}

			return o;
		}
1250382
function clone(obj, json) {
    if (json)
        return JSON.parse(JSON.stringify(obj));
    return _clone(obj);
}
538141
function clone(map) {
  return map instanceof SourceMapGenerator
    ? SourceMapGenerator.fromSourceMap(new SourceMapConsumer(map.toJSON()))
    : map;
}
769463
function cloneField (v) {
  if (v === null || v === undefined) {
    return v
  } if (Array.isArray(v)) {
    return v.map(cloneField)
  } else if (typeof v === 'object') {
    if ('saveAsJSON' in v) {
      return v.saveAsJSON()
    }
    return Object.assign({}, v)
  }
  return v
}
1236605
function(source) {
		if (helpers.isArray(source)) {
			return source.map(helpers.clone);
		}

		if (helpers.isObject(source)) {
			var target = {};
			var keys = Object.keys(source);
			var klen = keys.length;
			var k = 0;

			for (; k < klen; ++k) {
				target[keys[k]] = helpers.clone(source[keys[k]]);
			}

			return target;
		}

		return source;
	}
1182253
function cloneById (v, k) {
    if (Array.isArray(v)) {
      let match = find(v, it => String(it[options.idField]) === String(k));
      return match? cloneDeep(match) : (options.keepOrig? k : null);
    } else {
      return String(v[options.idField]) === String(k)? cloneDeep(v) : (options.keepOrig? k : null);
    }
  }
429490
public static <T extends Object> T cloneSerializable(T source) {
        ByteArrayOutputStream baos = null;
        ObjectOutputStream oos = null;
        ByteArrayInputStream bais = null;
        ObjectInputStream ois = null;
        try {
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(source);

            bais = new ByteArrayInputStream(baos.toByteArray());
            ois = new ObjectInputStream(bais);
            return (T) ois.readObject();
        } catch (IOException e) {
            return null;
        } catch (ClassNotFoundException e) {
            return null;
        } finally {
            closeQuietly(baos, oos, bais, ois);
        }
    }
892484
function _extend(obj, from) {
        for ( let key in from ) if ( hop.call(from, key) ) {
            obj[key] = from[key];
        }
        return obj;
    }
58343
function cloneAndInvoke(obj){
  var clone = Array.isArray(obj) ? [] : {};
  for (var key in obj) {
    if (obj[key] !== null && typeof(obj[key])=="object") {
      clone[key] = cloneAndInvoke(obj[key]);
    }else if(typeof(obj[key])=="function"){
      clone[key] = obj[key]();
    }else{
      clone[key] = obj[key];
    }
  }
  return clone
}
1008754
@SuppressWarnings("unchecked")
    protected <T> T cloneInternal(final T o, final Map<Object, Object> clones) throws IllegalAccessException {
        if (o == null) {
            return null;
        }
        if (o == this) {
            return null;
        }
        if (this.ignoredInstances.containsKey(o)) {
            return o;
        }
        final Class<T> clz = (Class<T>)o.getClass();
        if (clz.isEnum()) {
            return o;
        }
        // skip cloning ignored classes
        if (this.nullInstead.contains(clz)) {
            return null;
        }
        if (this.ignored.contains(clz)) {
            return o;
        }
        final Object clonedPreviously = clones != null ? clones.get(o) : null;
        if (clonedPreviously != null) {
            return (T)clonedPreviously;
        }

        final Object fastClone = fastClone(o, clones);
        if (fastClone != null) {
            if (clones != null) {
                clones.put(o, fastClone);
            }
            return (T)fastClone;
        }

        if (this.dumpClonedClasses) {
            System.out.println("clone>" + clz);
        }
        if (clz.isArray()) {
            final int length = Array.getLength(o);
            final T newInstance = (T)Array.newInstance(clz.getComponentType(), length);
            clones.put(o, newInstance);
            for (int i = 0; i < length; i++) {
                final Object v = Array.get(o, i);
                final Object clone = clones != null ? cloneInternal(v, clones) : v;
                Array.set(newInstance, i, clone);
            }
            return newInstance;
        }

        T newInstance = null;
        try {
            newInstance = clz.newInstance();
        } catch (Exception e) {
            throw new RuntimeException("Unable To instantiate object from class " + clz.getName(), e);
        }

        if (clones != null) {
            clones.put(o, newInstance);
        }
        final List<Field> fields = allFields(clz);
        for (final Field field : fields) {
            if (!Modifier.isStatic(field.getModifiers())) {
                if (this.nullTransient && Modifier.isTransient(field.getModifiers())) {
                    // request by Jonathan : transient fields can be null-ed
                    final Class<?> type = field.getType();
                    if (!type.isPrimitive()) {
                        field.set(newInstance, null);
                    }
                } else {
                    final Object fieldObject = field.get(o);
                    final Object fieldObjectClone = clones != null ? cloneInternal(fieldObject, clones) : fieldObject;
                    field.set(newInstance, fieldObjectClone);
                    if (this.dumpClonedClasses && (fieldObjectClone != fieldObject)) {
                        System.out.println("cloned field>" + field + "  -- of class " + o.getClass());
                    }
                }
            }
        }
        return newInstance;
    }
648051
function cloneWrap(obj, circularValue) {
  circularValue = safeDeepClone(undefined, [], circularValue);
  return safeDeepClone(circularValue, [], obj);
}
315737
function clone (thing) {
  var copy = {};
  var value;

  for (var key in thing) {
    value = thing[key];

    if (!value) {
      copy[key] = value;
    } else if (momentum.isMoment(value)) {
      copy[key] = value.clone();
    } else if (value._isStylesConfiguration) {
      copy[key] = clone(value);
    } else {
      copy[key] = value;
    }
  }

  return copy;
}