UNPKG

@mucfe/matui

Version:

基于Vue和ElementUi的PC组件库

83 lines (65 loc) 1.95 kB
"use strict"; exports.__esModule = true; exports.default = copy; var _utils = require("./utils"); // utils /** * @function copy * * @description * deeply copy the object to a new object of the same type * * @param {any} object the object to copy * @param {any} [realm=global] the realm to check instanceof in * @returns {any} the copied object */ function copy(object, realm) { if (realm === void 0) { realm = global; } var cache = (0, _utils.getNewCache)(); var handleCopy = function handleCopy(object) { if (!(0, _utils.isObjectCopyable)(object, cache)) { return object; } if (Array.isArray(object)) { cache.add(object); return (0, _utils.copyArray)(object, handleCopy, realm); } if (object.constructor === realm.Object) { cache.add(object); return (0, _utils.copyObject)(object, handleCopy, realm, true); } if (object instanceof realm.Date) { return new Date(object.getTime()); } if (object instanceof realm.RegExp) { return (0, _utils.copyRegExp)(object, realm); } if (realm.Map && object instanceof realm.Map) { cache.add(object); return (0, _utils.copyMap)(object, handleCopy, realm); } if (realm.Set && object instanceof realm.Set) { cache.add(object); return (0, _utils.copySet)(object, handleCopy, realm); } if (realm.Buffer && realm.Buffer.isBuffer(object)) { return (0, _utils.copyBuffer)(object, realm); } if (realm.ArrayBuffer) { if (realm.ArrayBuffer.isView(object)) { return (0, _utils.copyTypedArray)(object); } if (object instanceof realm.ArrayBuffer) { return (0, _utils.copyArrayBuffer)(object); } } if ((0, _utils.shouldObjectBeCopied)(object, realm)) { cache.add(object); return (0, _utils.copyObject)(object, handleCopy, realm); } return object; }; return handleCopy(object); }