All files / src clone.js

100% Statements 20/20
100% Branches 9/9
100% Functions 1/1
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 1x 1x 14x 14x 14x 2x 14x 2x 2x 12x 2x 10x 4x 4x 4x 4x 14x 14x 14x  
import { isDate, isRegexp, isDataView, isBuffer } from './constants.js'
 
export function cloneStructures (x, str) {
  let tmp
 
  if (str === isDate) {
    tmp = new Date(+x)
  } else if (str === isRegexp) {
    tmp = new RegExp(x.source, x.flags)
    tmp.lastIndex = x.lastIndex
  } else if (str === isDataView) {
    tmp = new x.constructor(cloneStructures(x.buffer, isBuffer))
  } else if (str === isBuffer) {
    tmp = x.slice(0)
  } else if (str.slice(-6) === 'Array]') {
    tmp = x.constructor.from(x)
  }
 
  return tmp
}