All files index.js

94.12% Statements 16/17
94.12% Branches 16/17
100% Functions 1/1
94.12% Lines 16/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x   25x         17x       8x 1x       7x 1x       6x 1x       5x 3x       2x 2x 2x 3x   2x            
module.exports = function clone (src) {
  // Null/undefined/functions/etc
  if (
    !src ||
    typeof src !== 'object' ||
    typeof src === 'function'
  ) {
    return src
  }
 
  // DOM Node
  if (src.nodeType && 'cloneNode' in src) {
    return src.cloneNode(true)
  }
 
  // Date
  if (src instanceof Date) {
    return new Date(src.getTime())
  }
 
  // RegExp
  if (src instanceof RegExp) {
    return new RegExp(src)
  }
 
  // Arrays
  if (Array.isArray(src)) {
    return src.map(clone)
  }
 
  // Object
  Eif (src instanceof Object) {
    var obj = {}
    for (var key in src) {
      obj[key] = clone(src[key])
    }
    return obj
  }
 
  // ???
  return src
}