all files / lib/deps/ clone.js

100% Statements 31/31
94.44% Branches 17/18
100% Functions 2/2
100% Lines 30/30
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                    1141779× 1141779× 1141779×   1141779× 756934×     384845× 117982× 117982× 339430×   117982×         266863× 2210×     264653× 2115×     262538× 262538× 616463× 616433× 616433× 602226×       262538×    
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
var _isBinaryObject = require('./binary/isBinaryObject');
 
var _isBinaryObject2 = _interopRequireDefault(_isBinaryObject);
 
var _cloneBinaryObject = require('./binary/cloneBinaryObject');
 
var _cloneBinaryObject2 = _interopRequireDefault(_cloneBinaryObject);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function clone(object) {
  var newObject;
  var i;
  var len;
 
  if (!object || typeof object !== 'object') {
    return object;
  }
 
  if (Array.isArray(object)) {
    newObject = [];
    for (i = 0, len = object.length; i < len; i++) {
      newObject[i] = clone(object[i]);
    }
    return newObject;
  }
 
  // special case: to avoid inconsistencies between IndexedDB
  // and other backends, we automatically stringify Dates
  if (object instanceof Date) {
    return object.toISOString();
  }
 
  if ((0, _isBinaryObject2.default)(object)) {
    return (0, _cloneBinaryObject2.default)(object);
  }
 
  newObject = {};
  for (i in object) {
    if (Object.prototype.hasOwnProperty.call(object, i)) {
      var value = clone(object[i]);
      if (typeof value !== 'undefined') {
        newObject[i] = value;
      }
    }
  }
  return newObject;
}
 
exports.default = clone;
module.exports = exports['default'];