es2015/clone.js
function cloneValue(value, traversedValues) {
  if (!(value instanceof Object)) {
    return value
  }
  
  if (value instanceof Boolean) {
    return new Boolean(value.valueOf())
  }

  if (value instanceof Number) {
    return new Number(value.valueOf())
  }
  
  if (value instanceof String) {
    return new String(value.valueOf())
  }
  
  if (value instanceof Date) {
    return new Date(value.valueOf())
  }
  
  if (value instanceof RegExp) {
    return new RegExp(value.source, value.flags)
  }
  
  if ((typeof Blob === "function") && (value instanceof Blob)) {
    return value // immutable
  }
  
  if ((typeof File === "function") && (value instanceof File)) {
    return value // immutable
  }
  
  if ((typeof FileList === "function") && (value instanceof FileList)) {
    return value // immutable
  }
  
  if ((typeof ArrayBuffer === "function") && (value instanceof ArrayBuffer)) {
    return value.slice()
  }

  if ((typeof DataView === "function") && (value instanceof DataView)) {
    return new DataView(
      value.buffer.slice(),
      value.byteOffset,
      value.byteLength
    )
  }
  
  let isTypedArray = TYPED_ARRAY_TYPES.some(type => value instanceof type)
  if (isTypedArray) {
    return value.subarray()
  }
  
  if ((typeof ImageData === "function") && (value instanceof ImageData)) {
    return new ImageData(value.data, value.width, value.height)
  }

  if ((typeof ImageBitmap === "function") && (value instanceof ImageBitmap)) {
    return value
  }
  
  if (value instanceof Array) {
    return cloneArray(value, traversedValues)
  }
  
  if (value instanceof Map) {
    return cloneMap(value, traversedValues)
  }
  
  if (value instanceof Set) {
    return cloneSet(value, traversedValues)
  }

  if (isPlainObjectOrEntity(value)) {
    return cloneObject(value, traversedValues)
  }

  throw new Error(`Unsupported argument type: ${value}`)
}
function cloneValue(value, traversedValues) {
  if (!(value instanceof Object)) {
    return value
  }
  
  if (value instanceof Boolean) {
    return new Boolean(value.valueOf())
  }

  if (value instanceof Number) {
    return new Number(value.valueOf())
  }
  
  if (value instanceof String) {
    return new String(value.valueOf())
  }
  
  if (value instanceof Date) {
    return new Date(value.valueOf())
  }
  
  if (value instanceof RegExp) {
    return new RegExp(value.source, value.flags)
  }
  
  if ((typeof Blob === "function") && (value instanceof Blob)) {
    return value // immutable
  }
  
  if ((typeof File === "function") && (value instanceof File)) {
    return value // immutable
  }
  
  if ((typeof FileList === "function") && (value instanceof FileList)) {
    return value // immutable
  }
  
  if ((typeof ArrayBuffer === "function") && (value instanceof ArrayBuffer)) {
    return value.slice()
  }

  if ((typeof DataView === "function") && (value instanceof DataView)) {
    return new DataView(
      value.buffer.slice(),
      value.byteOffset,
      value.byteLength
    )
  }
  
  let isTypedArray = TYPED_ARRAY_TYPES.some(type => value instanceof type)
  if (isTypedArray) {
    return value.subarray()
  }
  
  if ((typeof ImageData === "function") && (value instanceof ImageData)) {
    return new ImageData(value.data, value.width, value.height)
  }

  if ((typeof ImageBitmap === "function") && (value instanceof ImageBitmap)) {
    return value
  }
  
  if (value instanceof Array) {
    return cloneArray(value, traversedValues)
  }
  
  if (value instanceof Map) {
    return cloneMap(value, traversedValues)
  }
  
  if (value instanceof Set) {
    return cloneSet(value, traversedValues)
  }

  if (isPlainObjectOrEntity(value)) {
    return cloneObject(value, traversedValues)
  }

  throw new Error(`Unsupported argument type: ${value}`)
}
function cloneValue ( value , traversedValues ) { if ( ! ( value instanceof Object ) ) { return value } if ( value instanceof Boolean ) { return new Boolean ( value . valueOf ( ) ) } if ( value instanceof Number ) { return new Number ( value . valueOf ( ) ) } if ( value instanceof String ) { return new String ( value . valueOf ( ) ) } if ( value instanceof Date ) { return new Date ( value . valueOf ( ) ) } if ( value instanceof RegExp ) { return new RegExp ( value . source , value . flags ) } if ( ( typeof Blob === "function" ) && ( value instanceof Blob ) ) { return value // immutable } if ( ( typeof File === "function" ) && ( value instanceof File ) ) { return value // immutable } if ( ( typeof FileList === "function" ) && ( value instanceof FileList ) ) { return value // immutable } if ( ( typeof ArrayBuffer === "function" ) && ( value instanceof ArrayBuffer ) ) { return value . slice ( ) } if ( ( typeof DataView === "function" ) && ( value instanceof DataView ) ) { return new DataView ( value . buffer . slice ( ) , value . byteOffset , value . byteLength ) } let isTypedArray = TYPED_ARRAY_TYPES . some ( type => value instanceof type ) if ( isTypedArray ) { return value . subarray ( ) } if ( ( typeof ImageData === "function" ) && ( value instanceof ImageData ) ) { return new ImageData ( value . data , value . width , value . height ) } if ( ( typeof ImageBitmap === "function" ) && ( value instanceof ImageBitmap ) ) { return value } if ( value instanceof Array ) { return cloneArray ( value , traversedValues ) } if ( value instanceof Map ) { return cloneMap ( value , traversedValues ) } if ( value instanceof Set ) { return cloneSet ( value , traversedValues ) } if ( isPlainObjectOrEntity ( value ) ) { return cloneObject ( value , traversedValues ) } throw new Error ( ` ${ value } ` ) }
Clones the provided value using the structured clone algorithm.

@param {*} value The value to clone.
@param {Map<Object, Object>} traversedValues A map of traversed
non-primitive keys and values. The keys are the keys and values
traversed in the source structure or structures referencing this
structure, the values are the clones of the keys and values.
@return {*} The value clone.
Clones the provided value using the structured clone algorithm .