123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929 |
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.deepcopy = factory());
- }(this, (function () { 'use strict';
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
- function createCommonjsModule(fn, module) {
- return module = { exports: {} }, fn(module, module.exports), module.exports;
- }
- var typeDetect = createCommonjsModule(function (module, exports) {
- (function (global, factory) {
- module.exports = factory() ;
- }(commonjsGlobal, (function () {
-
- var promiseExists = typeof Promise === 'function';
-
- var globalObject = typeof self === 'object' ? self : commonjsGlobal;
- var symbolExists = typeof Symbol !== 'undefined';
- var mapExists = typeof Map !== 'undefined';
- var setExists = typeof Set !== 'undefined';
- var weakMapExists = typeof WeakMap !== 'undefined';
- var weakSetExists = typeof WeakSet !== 'undefined';
- var dataViewExists = typeof DataView !== 'undefined';
- var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
- var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
- var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
- var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
- var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
- var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
- var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
- var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
- var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
- var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
- var toStringLeftSliceLength = 8;
- var toStringRightSliceLength = -1;
-
- function typeDetect(obj) {
-
- var typeofObj = typeof obj;
- if (typeofObj !== 'object') {
- return typeofObj;
- }
-
- if (obj === null) {
- return 'null';
- }
-
- if (obj === globalObject) {
- return 'global';
- }
-
- if (
- Array.isArray(obj) &&
- (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
- ) {
- return 'Array';
- }
-
-
- if (typeof window === 'object' && window !== null) {
-
- if (typeof window.location === 'object' && obj === window.location) {
- return 'Location';
- }
-
- if (typeof window.document === 'object' && obj === window.document) {
- return 'Document';
- }
- if (typeof window.navigator === 'object') {
-
- if (typeof window.navigator.mimeTypes === 'object' &&
- obj === window.navigator.mimeTypes) {
- return 'MimeTypeArray';
- }
-
- if (typeof window.navigator.plugins === 'object' &&
- obj === window.navigator.plugins) {
- return 'PluginArray';
- }
- }
- if ((typeof window.HTMLElement === 'function' ||
- typeof window.HTMLElement === 'object') &&
- obj instanceof window.HTMLElement) {
-
- if (obj.tagName === 'BLOCKQUOTE') {
- return 'HTMLQuoteElement';
- }
-
- if (obj.tagName === 'TD') {
- return 'HTMLTableDataCellElement';
- }
-
- if (obj.tagName === 'TH') {
- return 'HTMLTableHeaderCellElement';
- }
- }
- }
-
- var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
- if (typeof stringTag === 'string') {
- return stringTag;
- }
- var objPrototype = Object.getPrototypeOf(obj);
-
- if (objPrototype === RegExp.prototype) {
- return 'RegExp';
- }
-
- if (objPrototype === Date.prototype) {
- return 'Date';
- }
-
- if (promiseExists && objPrototype === Promise.prototype) {
- return 'Promise';
- }
-
- if (setExists && objPrototype === Set.prototype) {
- return 'Set';
- }
-
- if (mapExists && objPrototype === Map.prototype) {
- return 'Map';
- }
-
- if (weakSetExists && objPrototype === WeakSet.prototype) {
- return 'WeakSet';
- }
-
- if (weakMapExists && objPrototype === WeakMap.prototype) {
- return 'WeakMap';
- }
-
- if (dataViewExists && objPrototype === DataView.prototype) {
- return 'DataView';
- }
-
- if (mapExists && objPrototype === mapIteratorPrototype) {
- return 'Map Iterator';
- }
-
- if (setExists && objPrototype === setIteratorPrototype) {
- return 'Set Iterator';
- }
-
- if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
- return 'Array Iterator';
- }
-
- if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
- return 'String Iterator';
- }
-
- if (objPrototype === null) {
- return 'Object';
- }
- return Object
- .prototype
- .toString
- .call(obj)
- .slice(toStringLeftSliceLength, toStringRightSliceLength);
- }
- return typeDetect;
- })));
- });
- const isBufferExists = typeof Buffer !== 'undefined';
- const isBufferFromExists = isBufferExists && typeof Buffer.from !== 'undefined';
- const isBuffer = isBufferExists
- ?
- function isBuffer(value) {
- return Buffer.isBuffer(value);
- }
- :
- function isBuffer() {
- return false;
- };
- const copy = isBufferFromExists
- ?
- function copy(value) {
- return Buffer.from(value);
- }
- : isBufferExists
- ?
- function copy(value) {
- return new Buffer(value);
- }
- :
- function copy(value) {
- return value;
- };
-
- function detectType(value) {
-
-
- if (isBuffer(value)) {
- return 'Buffer';
- }
- return typeDetect(value);
- }
-
- const collectionTypeSet = new Set([
- 'Arguments',
- 'Array',
- 'Map',
- 'Object',
- 'Set'
- ]);
-
- function get(collection, key, type = null) {
- const valueType = type || detectType(collection);
- switch (valueType) {
- case 'Arguments':
- case 'Array':
- case 'Object':
- return collection[key];
- case 'Map':
- return collection.get(key);
- case 'Set':
-
-
- return key;
- }
- }
-
- function isCollection(type) {
- return collectionTypeSet.has(type);
- }
-
- function set(collection, key, value, type = null) {
- const valueType = type || detectType(collection);
- switch (valueType) {
- case 'Arguments':
- case 'Array':
- case 'Object':
- collection[key] = value;
- break;
- case 'Map':
- collection.set(key, value);
- break;
- case 'Set':
- collection.add(value);
- break;
- }
- return collection;
- }
- const freeGlobalThis =
- typeof globalThis !== 'undefined' &&
- globalThis !== null &&
- globalThis.Object === Object &&
- globalThis;
- const freeGlobal =
- typeof global !== 'undefined' &&
- global !== null &&
- global.Object === Object &&
- global;
- const freeSelf =
- typeof self !== 'undefined' &&
- self !== null &&
- self.Object === Object &&
- self;
- const globalObject =
- freeGlobalThis || freeGlobal || freeSelf || Function('return this')();
-
- function copyArrayBuffer(value) {
- return value.slice(0);
- }
-
- function copyBoolean(value) {
- return new Boolean(value.valueOf());
- }
-
- function copyDataView(value) {
-
- return new DataView(value.buffer);
- }
-
- function copyBuffer(value) {
- return copy(value);
- }
-
- function copyDate(value) {
- return new Date(value.getTime());
- }
-
- function copyNumber(value) {
- return new Number(value);
- }
-
- function copyRegExp(value) {
- return new RegExp(value.source, value.flags);
- }
-
- function copyString(value) {
- return new String(value);
- }
-
- function copyTypedArray(value, type) {
- const typedArray = globalObject[type];
- if (typedArray.from) {
- return globalObject[type].from(value);
- }
- return new globalObject[type](value);
- }
-
- function shallowCopy(value) {
- return value;
- }
-
- function getEmptyArray() {
- return [];
- }
-
- function getEmptyMap() {
- return new Map();
- }
-
- function getEmptyObject() {
- return {};
- }
-
- function getEmptySet() {
- return new Set();
- }
- var copyMap = new Map([
-
- ['ArrayBuffer', copyArrayBuffer],
- ['Boolean', copyBoolean],
- ['Buffer', copyBuffer],
- ['DataView', copyDataView],
- ['Date', copyDate],
- ['Number', copyNumber],
- ['RegExp', copyRegExp],
- ['String', copyString],
-
-
- ['Float32Array', copyTypedArray],
- ['Float64Array', copyTypedArray],
- ['Int16Array', copyTypedArray],
- ['Int32Array', copyTypedArray],
- ['Int8Array', copyTypedArray],
- ['Uint16Array', copyTypedArray],
- ['Uint32Array', copyTypedArray],
- ['Uint8Array', copyTypedArray],
- ['Uint8ClampedArray', copyTypedArray],
-
- ['Array Iterator', shallowCopy],
- ['Map Iterator', shallowCopy],
- ['Promise', shallowCopy],
- ['Set Iterator', shallowCopy],
- ['String Iterator', shallowCopy],
- ['function', shallowCopy],
- ['global', shallowCopy],
-
- ['WeakMap', shallowCopy],
- ['WeakSet', shallowCopy],
-
- ['boolean', shallowCopy],
- ['null', shallowCopy],
- ['number', shallowCopy],
- ['string', shallowCopy],
- ['symbol', shallowCopy],
- ['undefined', shallowCopy],
-
-
- ['Arguments', getEmptyArray],
- ['Array', getEmptyArray],
- ['Map', getEmptyMap],
- ['Object', getEmptyObject],
- ['Set', getEmptySet]
-
-
-
-
-
-
-
-
-
-
- ]);
-
- function noop() {}
-
- function copy$1(value, type = null, customizer = noop) {
- if (arguments.length === 2 && typeof type === 'function') {
- customizer = type;
- type = null;
- }
- const valueType = type || detectType(value);
- const copyFunction = copyMap.get(valueType);
- if (valueType === 'Object') {
- const result = customizer(value, valueType);
- if (result !== undefined) {
- return result;
- }
- }
-
- return copyFunction ? copyFunction(value, valueType) : value;
- }
-
- function deepcopy(value, options = {}) {
- if (typeof options === 'function') {
- options = {
- customizer: options
- };
- }
- const {
-
- customizer
-
-
- } = options;
- const valueType = detectType(value);
- if (!isCollection(valueType)) {
- return recursiveCopy(value, null, null, null);
- }
- const copiedValue = copy$1(value, valueType, customizer);
- const references = new WeakMap([[value, copiedValue]]);
- const visited = new WeakSet([value]);
- return recursiveCopy(value, copiedValue, references, visited);
- }
-
- function recursiveCopy(value, clone, references, visited, customizer) {
- const type = detectType(value);
- const copiedValue = copy$1(value, type);
-
- if (!isCollection(type)) {
- return copiedValue;
- }
- let keys;
- switch (type) {
- case 'Arguments':
- case 'Array':
- keys = Object.keys(value);
- break;
- case 'Object':
- keys = Object.keys(value);
- keys.push(...Object.getOwnPropertySymbols(value));
- break;
- case 'Map':
- case 'Set':
- keys = value.keys();
- break;
- }
-
- for (let collectionKey of keys) {
- const collectionValue = get(value, collectionKey, type);
- if (visited.has(collectionValue)) {
-
- set(clone, collectionKey, references.get(collectionValue), type);
- } else {
- const collectionValueType = detectType(collectionValue);
- const copiedCollectionValue = copy$1(collectionValue, collectionValueType);
-
- if (isCollection(collectionValueType)) {
- references.set(collectionValue, copiedCollectionValue);
- visited.add(collectionValue);
- }
- set(
- clone,
- collectionKey,
- recursiveCopy(
- collectionValue,
- copiedCollectionValue,
- references,
- visited),
- type
- );
- }
- }
- // TODO: isSealed/isFrozen/isExtensible
- return clone;
- }
- return deepcopy;
- })));
- //# sourceMappingURL=deepcopy.js.map
|