UNPKG

@raona/sp

Version:

Raona utilities to work with Sharepoint using pnp/sp

39 lines (38 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Returns deep copy of object * @param obj Object to copy */ function deepCopy(obj) { var copy; if (null == obj || 'object' != typeof obj) return obj; if (obj instanceof Date) { copy = new Date(); copy.setTime(obj.getTime()); return copy; } if (obj instanceof ArrayBuffer) { copy = new ArrayBuffer(obj.byteLength); new Uint8Array(copy).set(new Uint8Array(obj)); return copy; } if (obj instanceof Array) { copy = []; for (var i = 0, len = obj.length; i < len; i++) { copy[i] = deepCopy(obj[i]); } return copy; } if (obj instanceof Object) { copy = {}; for (var attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = deepCopy(obj[attr]); } return copy; } throw new Error("Unable to copy obj! Its type isn't supported."); } exports.deepCopy = deepCopy;