Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-copy

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-copy - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

6

CHANGELOG.md
# fast-copy CHANGELOG
## 2.1.2
- Support `constructor` property override on object [#60](https://github.com/planttheidea/fast-copy/pull/60)
- Provide better support for `constructor` override on non-plain object types [#61](https://github.com/planttheidea/fast-copy/pull/61)
- Remove `tslint` in favor of `@typescript-eslint` [#62](https://github.com/planttheidea/fast-copy/pull/62)
## 2.1.1

@@ -4,0 +10,0 @@

249

dist/fast-copy.cjs.js
'use strict';
var toStringFunction = Function.prototype.toString;
var create = Object.create, defineProperty = Object.defineProperty, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols, getPrototypeOf = Object.getPrototypeOf;
var create = Object.create, defineProperty = Object.defineProperty, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols, getPrototypeOf$1 = Object.getPrototypeOf;
var _a = Object.prototype, hasOwnProperty = _a.hasOwnProperty, propertyIsEnumerable = _a.propertyIsEnumerable;
var SYMBOL_PROPERTIES = typeof getOwnPropertySymbols === 'function';
var WEAK_MAP = typeof WeakMap === 'function';
/**
* @enum
*
* @const {Object} SUPPORTS
*
* @property {boolean} SYMBOL_PROPERTIES are symbol properties supported
* @property {boolean} WEAKMAP is WeakMap supported
*/
var SUPPORTS = {
SYMBOL_PROPERTIES: typeof getOwnPropertySymbols === 'function',
WEAKMAP: typeof WeakMap === 'function',
};
/**
* @function createCache

@@ -26,19 +16,25 @@ *

*/
var createCache = function () {
if (SUPPORTS.WEAKMAP) {
return new WeakMap();
var createCache = (function () {
if (WEAK_MAP) {
return function () { return new WeakMap(); };
}
// tiny implementation of WeakMap
var object = create({
has: function (key) { return !!~object._keys.indexOf(key); },
set: function (key, value) {
object._keys.push(key);
object._values.push(value);
},
get: function (key) { return object._values[object._keys.indexOf(key)]; },
});
object._keys = [];
object._values = [];
return object;
};
var Cache = /** @class */ (function () {
function Cache() {
this._keys = [];
this._values = [];
}
Cache.prototype.has = function (key) {
return !!~this._keys.indexOf(key);
};
Cache.prototype.get = function (key) {
return this._values[this._keys.indexOf(key)];
};
Cache.prototype.set = function (key, value) {
this._keys.push(key);
this._values.push(value);
};
return Cache;
}());
return function () { return new Cache(); };
})();
/**

@@ -55,7 +51,7 @@ * @function getCleanClone

var getCleanClone = function (object, realm) {
if (!object.constructor) {
var prototype = object.__proto__ || getPrototypeOf$1(object);
if (!prototype) {
return create(null);
}
var Constructor = object.constructor;
var prototype = object.__proto__ || getPrototypeOf(object);
var Constructor = prototype.constructor;
if (Constructor === realm.Object) {

@@ -93,11 +89,8 @@ return prototype === realm.Object.prototype ? {} : create(prototype);

}
if (SUPPORTS.SYMBOL_PROPERTIES) {
if (SYMBOL_PROPERTIES) {
var symbols = getOwnPropertySymbols(object);
var length_1 = symbols.length;
if (length_1) {
for (var index = 0, symbol = void 0; index < length_1; index++) {
symbol = symbols[index];
if (propertyIsEnumerable.call(object, symbol)) {
clone[symbol] = handleCopy(object[symbol], cache);
}
for (var index = 0, length_1 = symbols.length, symbol = void 0; index < length_1; ++index) {
symbol = symbols[index];
if (propertyIsEnumerable.call(object, symbol)) {
clone[symbol] = handleCopy(object[symbol], cache);
}

@@ -124,30 +117,27 @@ }

cache.set(object, clone);
var properties = SUPPORTS.SYMBOL_PROPERTIES
var properties = SYMBOL_PROPERTIES
? getOwnPropertyNames(object).concat(getOwnPropertySymbols(object))
: getOwnPropertyNames(object);
var length = properties.length;
if (length) {
for (var index = 0, property = void 0, descriptor = void 0; index < length; index++) {
property = properties[index];
if (property !== 'callee' && property !== 'caller') {
descriptor = getOwnPropertyDescriptor(object, property);
if (descriptor) {
// Only clone the value if actually a value, not a getter / setter.
if (!descriptor.get && !descriptor.set) {
descriptor.value = handleCopy(object[property], cache);
}
try {
defineProperty(clone, property, descriptor);
}
catch (error) {
// Tee above can fail on node in edge cases, so fall back to the loose assignment.
clone[property] = descriptor.value;
}
for (var index = 0, length_2 = properties.length, property = void 0, descriptor = void 0; index < length_2; ++index) {
property = properties[index];
if (property !== 'callee' && property !== 'caller') {
descriptor = getOwnPropertyDescriptor(object, property);
if (descriptor) {
// Only clone the value if actually a value, not a getter / setter.
if (!descriptor.get && !descriptor.set) {
descriptor.value = handleCopy(object[property], cache);
}
else {
// In extra edge cases where the property descriptor cannot be retrived, fall back to
// the loose assignment.
clone[property] = handleCopy(object[property], cache);
try {
defineProperty(clone, property, descriptor);
}
catch (error) {
// Tee above can fail on node in edge cases, so fall back to the loose assignment.
clone[property] = descriptor.value;
}
}
else {
// In extra edge cases where the property descriptor cannot be retrived, fall back to
// the loose assignment.
clone[property] = handleCopy(object[property], cache);
}
}

@@ -188,3 +178,7 @@ }

var isArray = Array.isArray;
var getPrototypeOf = Object.getPrototypeOf;
var GLOBAL_THIS = (function () {
if (typeof globalThis !== 'undefined') {
return globalThis;
}
if (typeof self !== 'undefined') {

@@ -202,2 +196,3 @@ return self;

}
return this;
})();

@@ -208,3 +203,3 @@ /**

* @description
* copy an object deeply as much as possible
* copy an value deeply as much as possible
*

@@ -214,19 +209,17 @@ * If `strict` is applied, then all properties (including non-enumerable ones)

*
* The object is compared to the global constructors in the `realm` provided,
* The value is compared to the global constructors in the `realm` provided,
* and the native constructor is always used to ensure that extensions of native
* objects (allows in ES2015+) are maintained.
*
* @param object the object to copy
* @param value the value to copy
* @param [options] the options for copying with
* @param [options.isStrict] should the copy be strict
* @param [options.realm] the realm (this) object the object is copied from
* @returns the copied object
* @param [options.realm] the realm (this) value the value is copied from
* @returns the copied value
*/
function copy(object, options) {
function copy(value, options) {
// manually coalesced instead of default parameters for performance
var isStrict = !!(options && options.isStrict);
var realm = (options && options.realm) || GLOBAL_THIS;
var getObjectClone = isStrict
? getObjectCloneStrict
: getObjectCloneLoose;
var getObjectClone = isStrict ? getObjectCloneStrict : getObjectCloneLoose;
/**

@@ -236,31 +229,31 @@ * @function handleCopy

* @description
* copy the object recursively based on its type
* copy the value recursively based on its type
*
* @param object the object to copy
* @returns the copied object
* @param value the value to copy
* @returns the copied value
*/
var handleCopy = function (object, cache) {
if (!object || typeof object !== 'object') {
return object;
var handleCopy = function (value, cache) {
if (!value || typeof value !== 'object') {
return value;
}
if (cache.has(object)) {
return cache.get(object);
if (cache.has(value)) {
return cache.get(value);
}
var Constructor = object.constructor;
var prototype = value.__proto__ || getPrototypeOf(value);
var Constructor = prototype && prototype.constructor;
// plain objects
if (Constructor === realm.Object) {
return getObjectClone(object, realm, handleCopy, cache);
if (!Constructor || Constructor === realm.Object) {
return getObjectClone(value, realm, handleCopy, cache);
}
var clone;
// arrays
if (isArray(object)) {
if (isArray(value)) {
// if strict, include non-standard properties
if (isStrict) {
return getObjectCloneStrict(object, realm, handleCopy, cache);
return getObjectCloneStrict(value, realm, handleCopy, cache);
}
var length_1 = object.length;
clone = new Constructor();
cache.set(object, clone);
for (var index = 0; index < length_1; index++) {
clone[index] = handleCopy(object[index], cache);
cache.set(value, clone);
for (var index = 0, length_1 = value.length; index < length_1; ++index) {
clone[index] = handleCopy(value[index], cache);
}

@@ -270,16 +263,16 @@ return clone;

// dates
if (object instanceof realm.Date) {
return new Constructor(object.getTime());
if (value instanceof realm.Date) {
return new Constructor(value.getTime());
}
// regexps
if (object instanceof realm.RegExp) {
clone = new Constructor(object.source, object.flags || getRegExpFlags(object));
clone.lastIndex = object.lastIndex;
if (value instanceof realm.RegExp) {
clone = new Constructor(value.source, value.flags || getRegExpFlags(value));
clone.lastIndex = value.lastIndex;
return clone;
}
// maps
if (realm.Map && object instanceof realm.Map) {
if (realm.Map && value instanceof realm.Map) {
clone = new Constructor();
cache.set(object, clone);
object.forEach(function (value, key) {
cache.set(value, clone);
value.forEach(function (value, key) {
clone.set(key, handleCopy(value, cache));

@@ -290,6 +283,6 @@ });

// sets
if (realm.Set && object instanceof realm.Set) {
if (realm.Set && value instanceof realm.Set) {
clone = new Constructor();
cache.set(object, clone);
object.forEach(function (value) {
cache.set(value, clone);
value.forEach(function (value) {
clone.add(handleCopy(value, cache));

@@ -300,12 +293,12 @@ });

// blobs
if (realm.Blob && object instanceof realm.Blob) {
return object.slice(0, object.size, object.type);
if (realm.Blob && value instanceof realm.Blob) {
return value.slice(0, value.size, value.type);
}
// buffers (node-only)
if (realm.Buffer && realm.Buffer.isBuffer(object)) {
if (realm.Buffer && realm.Buffer.isBuffer(value)) {
clone = realm.Buffer.allocUnsafe
? realm.Buffer.allocUnsafe(object.length)
: new Constructor(object.length);
cache.set(object, clone);
object.copy(clone);
? realm.Buffer.allocUnsafe(value.length)
: new Constructor(value.length);
cache.set(value, clone);
value.copy(clone);
return clone;

@@ -316,33 +309,33 @@ }

// dataviews
if (realm.ArrayBuffer.isView(object)) {
clone = new Constructor(object.buffer.slice(0));
cache.set(object, clone);
if (realm.ArrayBuffer.isView(value)) {
clone = new Constructor(value.buffer.slice(0));
cache.set(value, clone);
return clone;
}
// arraybuffers
if (object instanceof realm.ArrayBuffer) {
clone = object.slice(0);
cache.set(object, clone);
if (value instanceof realm.ArrayBuffer) {
clone = value.slice(0);
cache.set(value, clone);
return clone;
}
}
// if the object cannot / should not be cloned, don't
// if the value cannot / should not be cloned, don't
if (
// promise-like
typeof object.then === 'function' ||
typeof value.then === 'function' ||
// errors
object instanceof Error ||
value instanceof Error ||
// weakmaps
(realm.WeakMap && object instanceof realm.WeakMap) ||
(realm.WeakMap && value instanceof realm.WeakMap) ||
// weaksets
(realm.WeakSet && object instanceof realm.WeakSet)) {
return object;
(realm.WeakSet && value instanceof realm.WeakSet)) {
return value;
}
// assume anything left is a custom constructor
return getObjectClone(object, realm, handleCopy, cache);
return getObjectClone(value, realm, handleCopy, cache);
};
return handleCopy(object, createCache());
return handleCopy(value, createCache());
}
// Adding reference to allow usage in CommonJS libraries compiled using TSC, which
// expects there to be a default property on the exported object. See
// expects there to be a default property on the exported value. See
// [#37](https://github.com/planttheidea/fast-copy/issues/37) for details.

@@ -354,11 +347,11 @@ copy.default = copy;

* @description
* copy the object with `strict` option pre-applied
* copy the value with `strict` option pre-applied
*
* @param object the object to copy
* @param value the value to copy
* @param [options] the options for copying with
* @param [options.realm] the realm (this) object the object is copied from
* @returns the copied object
* @param [options.realm] the realm (this) value the value is copied from
* @returns the copied value
*/
copy.strict = function strictCopy(object, options) {
return copy(object, {
copy.strict = function strictCopy(value, options) {
return copy(value, {
isStrict: true,

@@ -365,0 +358,0 @@ realm: options ? options.realm : void 0,

var toStringFunction = Function.prototype.toString;
var create = Object.create, defineProperty = Object.defineProperty, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols, getPrototypeOf = Object.getPrototypeOf;
var create = Object.create, defineProperty = Object.defineProperty, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols, getPrototypeOf$1 = Object.getPrototypeOf;
var _a = Object.prototype, hasOwnProperty = _a.hasOwnProperty, propertyIsEnumerable = _a.propertyIsEnumerable;
var SYMBOL_PROPERTIES = typeof getOwnPropertySymbols === 'function';
var WEAK_MAP = typeof WeakMap === 'function';
/**
* @enum
*
* @const {Object} SUPPORTS
*
* @property {boolean} SYMBOL_PROPERTIES are symbol properties supported
* @property {boolean} WEAKMAP is WeakMap supported
*/
var SUPPORTS = {
SYMBOL_PROPERTIES: typeof getOwnPropertySymbols === 'function',
WEAKMAP: typeof WeakMap === 'function',
};
/**
* @function createCache

@@ -24,19 +14,25 @@ *

*/
var createCache = function () {
if (SUPPORTS.WEAKMAP) {
return new WeakMap();
var createCache = (function () {
if (WEAK_MAP) {
return function () { return new WeakMap(); };
}
// tiny implementation of WeakMap
var object = create({
has: function (key) { return !!~object._keys.indexOf(key); },
set: function (key, value) {
object._keys.push(key);
object._values.push(value);
},
get: function (key) { return object._values[object._keys.indexOf(key)]; },
});
object._keys = [];
object._values = [];
return object;
};
var Cache = /** @class */ (function () {
function Cache() {
this._keys = [];
this._values = [];
}
Cache.prototype.has = function (key) {
return !!~this._keys.indexOf(key);
};
Cache.prototype.get = function (key) {
return this._values[this._keys.indexOf(key)];
};
Cache.prototype.set = function (key, value) {
this._keys.push(key);
this._values.push(value);
};
return Cache;
}());
return function () { return new Cache(); };
})();
/**

@@ -53,7 +49,7 @@ * @function getCleanClone

var getCleanClone = function (object, realm) {
if (!object.constructor) {
var prototype = object.__proto__ || getPrototypeOf$1(object);
if (!prototype) {
return create(null);
}
var Constructor = object.constructor;
var prototype = object.__proto__ || getPrototypeOf(object);
var Constructor = prototype.constructor;
if (Constructor === realm.Object) {

@@ -91,11 +87,8 @@ return prototype === realm.Object.prototype ? {} : create(prototype);

}
if (SUPPORTS.SYMBOL_PROPERTIES) {
if (SYMBOL_PROPERTIES) {
var symbols = getOwnPropertySymbols(object);
var length_1 = symbols.length;
if (length_1) {
for (var index = 0, symbol = void 0; index < length_1; index++) {
symbol = symbols[index];
if (propertyIsEnumerable.call(object, symbol)) {
clone[symbol] = handleCopy(object[symbol], cache);
}
for (var index = 0, length_1 = symbols.length, symbol = void 0; index < length_1; ++index) {
symbol = symbols[index];
if (propertyIsEnumerable.call(object, symbol)) {
clone[symbol] = handleCopy(object[symbol], cache);
}

@@ -122,30 +115,27 @@ }

cache.set(object, clone);
var properties = SUPPORTS.SYMBOL_PROPERTIES
var properties = SYMBOL_PROPERTIES
? getOwnPropertyNames(object).concat(getOwnPropertySymbols(object))
: getOwnPropertyNames(object);
var length = properties.length;
if (length) {
for (var index = 0, property = void 0, descriptor = void 0; index < length; index++) {
property = properties[index];
if (property !== 'callee' && property !== 'caller') {
descriptor = getOwnPropertyDescriptor(object, property);
if (descriptor) {
// Only clone the value if actually a value, not a getter / setter.
if (!descriptor.get && !descriptor.set) {
descriptor.value = handleCopy(object[property], cache);
}
try {
defineProperty(clone, property, descriptor);
}
catch (error) {
// Tee above can fail on node in edge cases, so fall back to the loose assignment.
clone[property] = descriptor.value;
}
for (var index = 0, length_2 = properties.length, property = void 0, descriptor = void 0; index < length_2; ++index) {
property = properties[index];
if (property !== 'callee' && property !== 'caller') {
descriptor = getOwnPropertyDescriptor(object, property);
if (descriptor) {
// Only clone the value if actually a value, not a getter / setter.
if (!descriptor.get && !descriptor.set) {
descriptor.value = handleCopy(object[property], cache);
}
else {
// In extra edge cases where the property descriptor cannot be retrived, fall back to
// the loose assignment.
clone[property] = handleCopy(object[property], cache);
try {
defineProperty(clone, property, descriptor);
}
catch (error) {
// Tee above can fail on node in edge cases, so fall back to the loose assignment.
clone[property] = descriptor.value;
}
}
else {
// In extra edge cases where the property descriptor cannot be retrived, fall back to
// the loose assignment.
clone[property] = handleCopy(object[property], cache);
}
}

@@ -186,3 +176,7 @@ }

var isArray = Array.isArray;
var getPrototypeOf = Object.getPrototypeOf;
var GLOBAL_THIS = (function () {
if (typeof globalThis !== 'undefined') {
return globalThis;
}
if (typeof self !== 'undefined') {

@@ -200,2 +194,3 @@ return self;

}
return this;
})();

@@ -206,3 +201,3 @@ /**

* @description
* copy an object deeply as much as possible
* copy an value deeply as much as possible
*

@@ -212,19 +207,17 @@ * If `strict` is applied, then all properties (including non-enumerable ones)

*
* The object is compared to the global constructors in the `realm` provided,
* The value is compared to the global constructors in the `realm` provided,
* and the native constructor is always used to ensure that extensions of native
* objects (allows in ES2015+) are maintained.
*
* @param object the object to copy
* @param value the value to copy
* @param [options] the options for copying with
* @param [options.isStrict] should the copy be strict
* @param [options.realm] the realm (this) object the object is copied from
* @returns the copied object
* @param [options.realm] the realm (this) value the value is copied from
* @returns the copied value
*/
function copy(object, options) {
function copy(value, options) {
// manually coalesced instead of default parameters for performance
var isStrict = !!(options && options.isStrict);
var realm = (options && options.realm) || GLOBAL_THIS;
var getObjectClone = isStrict
? getObjectCloneStrict
: getObjectCloneLoose;
var getObjectClone = isStrict ? getObjectCloneStrict : getObjectCloneLoose;
/**

@@ -234,31 +227,31 @@ * @function handleCopy

* @description
* copy the object recursively based on its type
* copy the value recursively based on its type
*
* @param object the object to copy
* @returns the copied object
* @param value the value to copy
* @returns the copied value
*/
var handleCopy = function (object, cache) {
if (!object || typeof object !== 'object') {
return object;
var handleCopy = function (value, cache) {
if (!value || typeof value !== 'object') {
return value;
}
if (cache.has(object)) {
return cache.get(object);
if (cache.has(value)) {
return cache.get(value);
}
var Constructor = object.constructor;
var prototype = value.__proto__ || getPrototypeOf(value);
var Constructor = prototype && prototype.constructor;
// plain objects
if (Constructor === realm.Object) {
return getObjectClone(object, realm, handleCopy, cache);
if (!Constructor || Constructor === realm.Object) {
return getObjectClone(value, realm, handleCopy, cache);
}
var clone;
// arrays
if (isArray(object)) {
if (isArray(value)) {
// if strict, include non-standard properties
if (isStrict) {
return getObjectCloneStrict(object, realm, handleCopy, cache);
return getObjectCloneStrict(value, realm, handleCopy, cache);
}
var length_1 = object.length;
clone = new Constructor();
cache.set(object, clone);
for (var index = 0; index < length_1; index++) {
clone[index] = handleCopy(object[index], cache);
cache.set(value, clone);
for (var index = 0, length_1 = value.length; index < length_1; ++index) {
clone[index] = handleCopy(value[index], cache);
}

@@ -268,16 +261,16 @@ return clone;

// dates
if (object instanceof realm.Date) {
return new Constructor(object.getTime());
if (value instanceof realm.Date) {
return new Constructor(value.getTime());
}
// regexps
if (object instanceof realm.RegExp) {
clone = new Constructor(object.source, object.flags || getRegExpFlags(object));
clone.lastIndex = object.lastIndex;
if (value instanceof realm.RegExp) {
clone = new Constructor(value.source, value.flags || getRegExpFlags(value));
clone.lastIndex = value.lastIndex;
return clone;
}
// maps
if (realm.Map && object instanceof realm.Map) {
if (realm.Map && value instanceof realm.Map) {
clone = new Constructor();
cache.set(object, clone);
object.forEach(function (value, key) {
cache.set(value, clone);
value.forEach(function (value, key) {
clone.set(key, handleCopy(value, cache));

@@ -288,6 +281,6 @@ });

// sets
if (realm.Set && object instanceof realm.Set) {
if (realm.Set && value instanceof realm.Set) {
clone = new Constructor();
cache.set(object, clone);
object.forEach(function (value) {
cache.set(value, clone);
value.forEach(function (value) {
clone.add(handleCopy(value, cache));

@@ -298,12 +291,12 @@ });

// blobs
if (realm.Blob && object instanceof realm.Blob) {
return object.slice(0, object.size, object.type);
if (realm.Blob && value instanceof realm.Blob) {
return value.slice(0, value.size, value.type);
}
// buffers (node-only)
if (realm.Buffer && realm.Buffer.isBuffer(object)) {
if (realm.Buffer && realm.Buffer.isBuffer(value)) {
clone = realm.Buffer.allocUnsafe
? realm.Buffer.allocUnsafe(object.length)
: new Constructor(object.length);
cache.set(object, clone);
object.copy(clone);
? realm.Buffer.allocUnsafe(value.length)
: new Constructor(value.length);
cache.set(value, clone);
value.copy(clone);
return clone;

@@ -314,33 +307,33 @@ }

// dataviews
if (realm.ArrayBuffer.isView(object)) {
clone = new Constructor(object.buffer.slice(0));
cache.set(object, clone);
if (realm.ArrayBuffer.isView(value)) {
clone = new Constructor(value.buffer.slice(0));
cache.set(value, clone);
return clone;
}
// arraybuffers
if (object instanceof realm.ArrayBuffer) {
clone = object.slice(0);
cache.set(object, clone);
if (value instanceof realm.ArrayBuffer) {
clone = value.slice(0);
cache.set(value, clone);
return clone;
}
}
// if the object cannot / should not be cloned, don't
// if the value cannot / should not be cloned, don't
if (
// promise-like
typeof object.then === 'function' ||
typeof value.then === 'function' ||
// errors
object instanceof Error ||
value instanceof Error ||
// weakmaps
(realm.WeakMap && object instanceof realm.WeakMap) ||
(realm.WeakMap && value instanceof realm.WeakMap) ||
// weaksets
(realm.WeakSet && object instanceof realm.WeakSet)) {
return object;
(realm.WeakSet && value instanceof realm.WeakSet)) {
return value;
}
// assume anything left is a custom constructor
return getObjectClone(object, realm, handleCopy, cache);
return getObjectClone(value, realm, handleCopy, cache);
};
return handleCopy(object, createCache());
return handleCopy(value, createCache());
}
// Adding reference to allow usage in CommonJS libraries compiled using TSC, which
// expects there to be a default property on the exported object. See
// expects there to be a default property on the exported value. See
// [#37](https://github.com/planttheidea/fast-copy/issues/37) for details.

@@ -352,11 +345,11 @@ copy.default = copy;

* @description
* copy the object with `strict` option pre-applied
* copy the value with `strict` option pre-applied
*
* @param object the object to copy
* @param value the value to copy
* @param [options] the options for copying with
* @param [options.realm] the realm (this) object the object is copied from
* @returns the copied object
* @param [options.realm] the realm (this) value the value is copied from
* @returns the copied value
*/
copy.strict = function strictCopy(object, options) {
return copy(object, {
copy.strict = function strictCopy(value, options) {
return copy(value, {
isStrict: true,

@@ -367,3 +360,3 @@ realm: options ? options.realm : void 0,

export default copy;
export { copy as default };
//# sourceMappingURL=fast-copy.esm.js.map
(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['fast-copy'] = factory());
}(this, (function () { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["fast-copy"] = factory());
})(this, (function () { 'use strict';
var toStringFunction = Function.prototype.toString;
var create = Object.create, defineProperty = Object.defineProperty, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols, getPrototypeOf = Object.getPrototypeOf;
var _a = Object.prototype, hasOwnProperty = _a.hasOwnProperty, propertyIsEnumerable = _a.propertyIsEnumerable;
/**
* @enum
*
* @const {Object} SUPPORTS
*
* @property {boolean} SYMBOL_PROPERTIES are symbol properties supported
* @property {boolean} WEAKMAP is WeakMap supported
*/
var SUPPORTS = {
SYMBOL_PROPERTIES: typeof getOwnPropertySymbols === 'function',
WEAKMAP: typeof WeakMap === 'function',
};
/**
* @function createCache
*
* @description
* get a new cache object to prevent circular references
*
* @returns the new cache object
*/
var createCache = function () {
if (SUPPORTS.WEAKMAP) {
return new WeakMap();
}
// tiny implementation of WeakMap
var object = create({
has: function (key) { return !!~object._keys.indexOf(key); },
set: function (key, value) {
object._keys.push(key);
object._values.push(value);
},
get: function (key) { return object._values[object._keys.indexOf(key)]; },
});
object._keys = [];
object._values = [];
return object;
};
/**
* @function getCleanClone
*
* @description
* get an empty version of the object with the same prototype it has
*
* @param object the object to build a clean clone from
* @param realm the realm the object resides in
* @returns the empty cloned object
*/
var getCleanClone = function (object, realm) {
if (!object.constructor) {
return create(null);
}
var Constructor = object.constructor;
var prototype = object.__proto__ || getPrototypeOf(object);
if (Constructor === realm.Object) {
return prototype === realm.Object.prototype ? {} : create(prototype);
}
if (~toStringFunction.call(Constructor).indexOf('[native code]')) {
try {
return new Constructor();
}
catch (_a) { }
}
return create(prototype);
};
/**
* @function getObjectCloneLoose
*
* @description
* get a copy of the object based on loose rules, meaning all enumerable keys
* and symbols are copied, but property descriptors are not considered
*
* @param object the object to clone
* @param realm the realm the object resides in
* @param handleCopy the function that handles copying the object
* @returns the copied object
*/
var getObjectCloneLoose = function (object, realm, handleCopy, cache) {
var clone = getCleanClone(object, realm);
// set in the cache immediately to be able to reuse the object recursively
cache.set(object, clone);
for (var key in object) {
if (hasOwnProperty.call(object, key)) {
clone[key] = handleCopy(object[key], cache);
}
}
if (SUPPORTS.SYMBOL_PROPERTIES) {
var symbols = getOwnPropertySymbols(object);
var length_1 = symbols.length;
if (length_1) {
for (var index = 0, symbol = void 0; index < length_1; index++) {
symbol = symbols[index];
if (propertyIsEnumerable.call(object, symbol)) {
clone[symbol] = handleCopy(object[symbol], cache);
}
}
}
}
return clone;
};
/**
* @function getObjectCloneStrict
*
* @description
* get a copy of the object based on strict rules, meaning all keys and symbols
* are copied based on the original property descriptors
*
* @param object the object to clone
* @param realm the realm the object resides in
* @param handleCopy the function that handles copying the object
* @returns the copied object
*/
var getObjectCloneStrict = function (object, realm, handleCopy, cache) {
var clone = getCleanClone(object, realm);
// set in the cache immediately to be able to reuse the object recursively
cache.set(object, clone);
var properties = SUPPORTS.SYMBOL_PROPERTIES
? getOwnPropertyNames(object).concat(getOwnPropertySymbols(object))
: getOwnPropertyNames(object);
var length = properties.length;
if (length) {
for (var index = 0, property = void 0, descriptor = void 0; index < length; index++) {
property = properties[index];
if (property !== 'callee' && property !== 'caller') {
descriptor = getOwnPropertyDescriptor(object, property);
if (descriptor) {
// Only clone the value if actually a value, not a getter / setter.
if (!descriptor.get && !descriptor.set) {
descriptor.value = handleCopy(object[property], cache);
}
try {
defineProperty(clone, property, descriptor);
}
catch (error) {
// Tee above can fail on node in edge cases, so fall back to the loose assignment.
clone[property] = descriptor.value;
}
}
else {
// In extra edge cases where the property descriptor cannot be retrived, fall back to
// the loose assignment.
clone[property] = handleCopy(object[property], cache);
}
}
}
}
return clone;
};
/**
* @function getRegExpFlags
*
* @description
* get the flags to apply to the copied regexp
*
* @param regExp the regexp to get the flags of
* @returns the flags for the regexp
*/
var getRegExpFlags = function (regExp) {
var flags = '';
if (regExp.global) {
flags += 'g';
}
if (regExp.ignoreCase) {
flags += 'i';
}
if (regExp.multiline) {
flags += 'm';
}
if (regExp.unicode) {
flags += 'u';
}
if (regExp.sticky) {
flags += 'y';
}
return flags;
};
var toStringFunction = Function.prototype.toString;
var create = Object.create, defineProperty = Object.defineProperty, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols, getPrototypeOf$1 = Object.getPrototypeOf;
var _a = Object.prototype, hasOwnProperty = _a.hasOwnProperty, propertyIsEnumerable = _a.propertyIsEnumerable;
var SYMBOL_PROPERTIES = typeof getOwnPropertySymbols === 'function';
var WEAK_MAP = typeof WeakMap === 'function';
/**
* @function createCache
*
* @description
* get a new cache object to prevent circular references
*
* @returns the new cache object
*/
var createCache = (function () {
if (WEAK_MAP) {
return function () { return new WeakMap(); };
}
var Cache = /** @class */ (function () {
function Cache() {
this._keys = [];
this._values = [];
}
Cache.prototype.has = function (key) {
return !!~this._keys.indexOf(key);
};
Cache.prototype.get = function (key) {
return this._values[this._keys.indexOf(key)];
};
Cache.prototype.set = function (key, value) {
this._keys.push(key);
this._values.push(value);
};
return Cache;
}());
return function () { return new Cache(); };
})();
/**
* @function getCleanClone
*
* @description
* get an empty version of the object with the same prototype it has
*
* @param object the object to build a clean clone from
* @param realm the realm the object resides in
* @returns the empty cloned object
*/
var getCleanClone = function (object, realm) {
var prototype = object.__proto__ || getPrototypeOf$1(object);
if (!prototype) {
return create(null);
}
var Constructor = prototype.constructor;
if (Constructor === realm.Object) {
return prototype === realm.Object.prototype ? {} : create(prototype);
}
if (~toStringFunction.call(Constructor).indexOf('[native code]')) {
try {
return new Constructor();
}
catch (_a) { }
}
return create(prototype);
};
/**
* @function getObjectCloneLoose
*
* @description
* get a copy of the object based on loose rules, meaning all enumerable keys
* and symbols are copied, but property descriptors are not considered
*
* @param object the object to clone
* @param realm the realm the object resides in
* @param handleCopy the function that handles copying the object
* @returns the copied object
*/
var getObjectCloneLoose = function (object, realm, handleCopy, cache) {
var clone = getCleanClone(object, realm);
// set in the cache immediately to be able to reuse the object recursively
cache.set(object, clone);
for (var key in object) {
if (hasOwnProperty.call(object, key)) {
clone[key] = handleCopy(object[key], cache);
}
}
if (SYMBOL_PROPERTIES) {
var symbols = getOwnPropertySymbols(object);
for (var index = 0, length_1 = symbols.length, symbol = void 0; index < length_1; ++index) {
symbol = symbols[index];
if (propertyIsEnumerable.call(object, symbol)) {
clone[symbol] = handleCopy(object[symbol], cache);
}
}
}
return clone;
};
/**
* @function getObjectCloneStrict
*
* @description
* get a copy of the object based on strict rules, meaning all keys and symbols
* are copied based on the original property descriptors
*
* @param object the object to clone
* @param realm the realm the object resides in
* @param handleCopy the function that handles copying the object
* @returns the copied object
*/
var getObjectCloneStrict = function (object, realm, handleCopy, cache) {
var clone = getCleanClone(object, realm);
// set in the cache immediately to be able to reuse the object recursively
cache.set(object, clone);
var properties = SYMBOL_PROPERTIES
? getOwnPropertyNames(object).concat(getOwnPropertySymbols(object))
: getOwnPropertyNames(object);
for (var index = 0, length_2 = properties.length, property = void 0, descriptor = void 0; index < length_2; ++index) {
property = properties[index];
if (property !== 'callee' && property !== 'caller') {
descriptor = getOwnPropertyDescriptor(object, property);
if (descriptor) {
// Only clone the value if actually a value, not a getter / setter.
if (!descriptor.get && !descriptor.set) {
descriptor.value = handleCopy(object[property], cache);
}
try {
defineProperty(clone, property, descriptor);
}
catch (error) {
// Tee above can fail on node in edge cases, so fall back to the loose assignment.
clone[property] = descriptor.value;
}
}
else {
// In extra edge cases where the property descriptor cannot be retrived, fall back to
// the loose assignment.
clone[property] = handleCopy(object[property], cache);
}
}
}
return clone;
};
/**
* @function getRegExpFlags
*
* @description
* get the flags to apply to the copied regexp
*
* @param regExp the regexp to get the flags of
* @returns the flags for the regexp
*/
var getRegExpFlags = function (regExp) {
var flags = '';
if (regExp.global) {
flags += 'g';
}
if (regExp.ignoreCase) {
flags += 'i';
}
if (regExp.multiline) {
flags += 'm';
}
if (regExp.unicode) {
flags += 'u';
}
if (regExp.sticky) {
flags += 'y';
}
return flags;
};
// utils
var isArray = Array.isArray;
var GLOBAL_THIS = (function () {
if (typeof self !== 'undefined') {
return self;
}
if (typeof window !== 'undefined') {
return window;
}
if (typeof global !== 'undefined') {
return global;
}
if (console && console.error) {
console.error('Unable to locate global object, returning "this".');
}
})();
/**
* @function copy
*
* @description
* copy an object deeply as much as possible
*
* If `strict` is applied, then all properties (including non-enumerable ones)
* are copied with their original property descriptors on both objects and arrays.
*
* The object is compared to the global constructors in the `realm` provided,
* and the native constructor is always used to ensure that extensions of native
* objects (allows in ES2015+) are maintained.
*
* @param object the object to copy
* @param [options] the options for copying with
* @param [options.isStrict] should the copy be strict
* @param [options.realm] the realm (this) object the object is copied from
* @returns the copied object
*/
function copy(object, options) {
// manually coalesced instead of default parameters for performance
var isStrict = !!(options && options.isStrict);
var realm = (options && options.realm) || GLOBAL_THIS;
var getObjectClone = isStrict
? getObjectCloneStrict
: getObjectCloneLoose;
/**
* @function handleCopy
*
* @description
* copy the object recursively based on its type
*
* @param object the object to copy
* @returns the copied object
*/
var handleCopy = function (object, cache) {
if (!object || typeof object !== 'object') {
return object;
}
if (cache.has(object)) {
return cache.get(object);
}
var Constructor = object.constructor;
// plain objects
if (Constructor === realm.Object) {
return getObjectClone(object, realm, handleCopy, cache);
}
var clone;
// arrays
if (isArray(object)) {
// if strict, include non-standard properties
if (isStrict) {
return getObjectCloneStrict(object, realm, handleCopy, cache);
}
var length_1 = object.length;
clone = new Constructor();
cache.set(object, clone);
for (var index = 0; index < length_1; index++) {
clone[index] = handleCopy(object[index], cache);
}
return clone;
}
// dates
if (object instanceof realm.Date) {
return new Constructor(object.getTime());
}
// regexps
if (object instanceof realm.RegExp) {
clone = new Constructor(object.source, object.flags || getRegExpFlags(object));
clone.lastIndex = object.lastIndex;
return clone;
}
// maps
if (realm.Map && object instanceof realm.Map) {
clone = new Constructor();
cache.set(object, clone);
object.forEach(function (value, key) {
clone.set(key, handleCopy(value, cache));
});
return clone;
}
// sets
if (realm.Set && object instanceof realm.Set) {
clone = new Constructor();
cache.set(object, clone);
object.forEach(function (value) {
clone.add(handleCopy(value, cache));
});
return clone;
}
// blobs
if (realm.Blob && object instanceof realm.Blob) {
return object.slice(0, object.size, object.type);
}
// buffers (node-only)
if (realm.Buffer && realm.Buffer.isBuffer(object)) {
clone = realm.Buffer.allocUnsafe
? realm.Buffer.allocUnsafe(object.length)
: new Constructor(object.length);
cache.set(object, clone);
object.copy(clone);
return clone;
}
// arraybuffers / dataviews
if (realm.ArrayBuffer) {
// dataviews
if (realm.ArrayBuffer.isView(object)) {
clone = new Constructor(object.buffer.slice(0));
cache.set(object, clone);
return clone;
}
// arraybuffers
if (object instanceof realm.ArrayBuffer) {
clone = object.slice(0);
cache.set(object, clone);
return clone;
}
}
// if the object cannot / should not be cloned, don't
if (
// promise-like
typeof object.then === 'function' ||
// errors
object instanceof Error ||
// weakmaps
(realm.WeakMap && object instanceof realm.WeakMap) ||
// weaksets
(realm.WeakSet && object instanceof realm.WeakSet)) {
return object;
}
// assume anything left is a custom constructor
return getObjectClone(object, realm, handleCopy, cache);
};
return handleCopy(object, createCache());
}
// Adding reference to allow usage in CommonJS libraries compiled using TSC, which
// expects there to be a default property on the exported object. See
// [#37](https://github.com/planttheidea/fast-copy/issues/37) for details.
copy.default = copy;
/**
* @function strictCopy
*
* @description
* copy the object with `strict` option pre-applied
*
* @param object the object to copy
* @param [options] the options for copying with
* @param [options.realm] the realm (this) object the object is copied from
* @returns the copied object
*/
copy.strict = function strictCopy(object, options) {
return copy(object, {
isStrict: true,
realm: options ? options.realm : void 0,
});
};
// utils
var isArray = Array.isArray;
var getPrototypeOf = Object.getPrototypeOf;
var GLOBAL_THIS = (function () {
if (typeof globalThis !== 'undefined') {
return globalThis;
}
if (typeof self !== 'undefined') {
return self;
}
if (typeof window !== 'undefined') {
return window;
}
if (typeof global !== 'undefined') {
return global;
}
if (console && console.error) {
console.error('Unable to locate global object, returning "this".');
}
return this;
})();
/**
* @function copy
*
* @description
* copy an value deeply as much as possible
*
* If `strict` is applied, then all properties (including non-enumerable ones)
* are copied with their original property descriptors on both objects and arrays.
*
* The value is compared to the global constructors in the `realm` provided,
* and the native constructor is always used to ensure that extensions of native
* objects (allows in ES2015+) are maintained.
*
* @param value the value to copy
* @param [options] the options for copying with
* @param [options.isStrict] should the copy be strict
* @param [options.realm] the realm (this) value the value is copied from
* @returns the copied value
*/
function copy(value, options) {
// manually coalesced instead of default parameters for performance
var isStrict = !!(options && options.isStrict);
var realm = (options && options.realm) || GLOBAL_THIS;
var getObjectClone = isStrict ? getObjectCloneStrict : getObjectCloneLoose;
/**
* @function handleCopy
*
* @description
* copy the value recursively based on its type
*
* @param value the value to copy
* @returns the copied value
*/
var handleCopy = function (value, cache) {
if (!value || typeof value !== 'object') {
return value;
}
if (cache.has(value)) {
return cache.get(value);
}
var prototype = value.__proto__ || getPrototypeOf(value);
var Constructor = prototype && prototype.constructor;
// plain objects
if (!Constructor || Constructor === realm.Object) {
return getObjectClone(value, realm, handleCopy, cache);
}
var clone;
// arrays
if (isArray(value)) {
// if strict, include non-standard properties
if (isStrict) {
return getObjectCloneStrict(value, realm, handleCopy, cache);
}
clone = new Constructor();
cache.set(value, clone);
for (var index = 0, length_1 = value.length; index < length_1; ++index) {
clone[index] = handleCopy(value[index], cache);
}
return clone;
}
// dates
if (value instanceof realm.Date) {
return new Constructor(value.getTime());
}
// regexps
if (value instanceof realm.RegExp) {
clone = new Constructor(value.source, value.flags || getRegExpFlags(value));
clone.lastIndex = value.lastIndex;
return clone;
}
// maps
if (realm.Map && value instanceof realm.Map) {
clone = new Constructor();
cache.set(value, clone);
value.forEach(function (value, key) {
clone.set(key, handleCopy(value, cache));
});
return clone;
}
// sets
if (realm.Set && value instanceof realm.Set) {
clone = new Constructor();
cache.set(value, clone);
value.forEach(function (value) {
clone.add(handleCopy(value, cache));
});
return clone;
}
// blobs
if (realm.Blob && value instanceof realm.Blob) {
return value.slice(0, value.size, value.type);
}
// buffers (node-only)
if (realm.Buffer && realm.Buffer.isBuffer(value)) {
clone = realm.Buffer.allocUnsafe
? realm.Buffer.allocUnsafe(value.length)
: new Constructor(value.length);
cache.set(value, clone);
value.copy(clone);
return clone;
}
// arraybuffers / dataviews
if (realm.ArrayBuffer) {
// dataviews
if (realm.ArrayBuffer.isView(value)) {
clone = new Constructor(value.buffer.slice(0));
cache.set(value, clone);
return clone;
}
// arraybuffers
if (value instanceof realm.ArrayBuffer) {
clone = value.slice(0);
cache.set(value, clone);
return clone;
}
}
// if the value cannot / should not be cloned, don't
if (
// promise-like
typeof value.then === 'function' ||
// errors
value instanceof Error ||
// weakmaps
(realm.WeakMap && value instanceof realm.WeakMap) ||
// weaksets
(realm.WeakSet && value instanceof realm.WeakSet)) {
return value;
}
// assume anything left is a custom constructor
return getObjectClone(value, realm, handleCopy, cache);
};
return handleCopy(value, createCache());
}
// Adding reference to allow usage in CommonJS libraries compiled using TSC, which
// expects there to be a default property on the exported value. See
// [#37](https://github.com/planttheidea/fast-copy/issues/37) for details.
copy.default = copy;
/**
* @function strictCopy
*
* @description
* copy the value with `strict` option pre-applied
*
* @param value the value to copy
* @param [options] the options for copying with
* @param [options.realm] the realm (this) value the value is copied from
* @returns the copied value
*/
copy.strict = function strictCopy(value, options) {
return copy(value, {
isStrict: true,
realm: options ? options.realm : void 0,
});
};
return copy;
return copy;
})));
}));
//# sourceMappingURL=fast-copy.js.map

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["fast-copy"]=t()}(this,(function(){"use strict";var e=Function.prototype.toString,t=Object.create,r=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols,i=Object.getPrototypeOf,a=Object.prototype,c=a.hasOwnProperty,u=a.propertyIsEnumerable,s="function"==typeof f,l="function"==typeof WeakMap,p=function(r,n){if(!r.constructor)return t(null);var o=r.constructor,f=r.__proto__||i(r);if(o===n.Object)return f===n.Object.prototype?{}:t(f);if(~e.call(o).indexOf("[native code]"))try{return new o}catch(e){}return t(f)},y=function(e,t,r,n){var o=p(e,t);for(var i in n.set(e,o),e)c.call(e,i)&&(o[i]=r(e[i],n));if(s){var a=f(e),l=a.length;if(l)for(var y=0,d=void 0;y<l;y++)d=a[y],u.call(e,d)&&(o[d]=r(e[d],n))}return o},d=function(e,t,i,a){var c=p(e,t);a.set(e,c);var u=s?o(e).concat(f(e)):o(e),l=u.length;if(l)for(var y=0,d=void 0,b=void 0;y<l;y++)if("callee"!==(d=u[y])&&"caller"!==d)if(b=n(e,d)){b.get||b.set||(b.value=i(e[d],a));try{r(c,d,b)}catch(e){c[d]=b.value}}else c[d]=i(e[d],a);return c},b=Array.isArray,g="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void(console&&console.error&&console.error('Unable to locate global object, returning "this".'));function v(e,r){var n=!(!r||!r.isStrict),o=r&&r.realm||g,f=n?d:y,i=function(e,t){if(!e||"object"!=typeof e)return e;if(t.has(e))return t.get(e);var r,a,c,u=e.constructor;if(u===o.Object)return f(e,o,i,t);if(b(e)){if(n)return d(e,o,i,t);var s=e.length;r=new u,t.set(e,r);for(var l=0;l<s;l++)r[l]=i(e[l],t);return r}if(e instanceof o.Date)return new u(e.getTime());if(e instanceof o.RegExp)return(r=new u(e.source,e.flags||(c="",(a=e).global&&(c+="g"),a.ignoreCase&&(c+="i"),a.multiline&&(c+="m"),a.unicode&&(c+="u"),a.sticky&&(c+="y"),c))).lastIndex=e.lastIndex,r;if(o.Map&&e instanceof o.Map)return r=new u,t.set(e,r),e.forEach((function(e,n){r.set(n,i(e,t))})),r;if(o.Set&&e instanceof o.Set)return r=new u,t.set(e,r),e.forEach((function(e){r.add(i(e,t))})),r;if(o.Blob&&e instanceof o.Blob)return e.slice(0,e.size,e.type);if(o.Buffer&&o.Buffer.isBuffer(e))return r=o.Buffer.allocUnsafe?o.Buffer.allocUnsafe(e.length):new u(e.length),t.set(e,r),e.copy(r),r;if(o.ArrayBuffer){if(o.ArrayBuffer.isView(e))return r=new u(e.buffer.slice(0)),t.set(e,r),r;if(e instanceof o.ArrayBuffer)return r=e.slice(0),t.set(e,r),r}return"function"==typeof e.then||e instanceof Error||o.WeakMap&&e instanceof o.WeakMap||o.WeakSet&&e instanceof o.WeakSet?e:f(e,o,i,t)};return i(e,function(){if(l)return new WeakMap;var e=t({has:function(t){return!!~e._keys.indexOf(t)},set:function(t,r){e._keys.push(t),e._values.push(r)},get:function(t){return e._values[e._keys.indexOf(t)]}});return e._keys=[],e._values=[],e}())}return v.default=v,v.strict=function(e,t){return v(e,{isStrict:!0,realm:t?t.realm:void 0})},v}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["fast-copy"]=t()}(this,(function(){"use strict";var e=Function.prototype.toString,t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.getOwnPropertySymbols,f=Object.getPrototypeOf,u=Object.prototype,a=u.hasOwnProperty,c=u.propertyIsEnumerable,s="function"==typeof i,l="function"==typeof WeakMap,p=function(){if(l)return function(){return new WeakMap};var e=function(){function e(){this._keys=[],this._values=[]}return e.prototype.has=function(e){return!!~this._keys.indexOf(e)},e.prototype.get=function(e){return this._values[this._keys.indexOf(e)]},e.prototype.set=function(e,t){this._keys.push(e),this._values.push(t)},e}();return function(){return new e}}(),y=function(n,r){var o=n.__proto__||f(n);if(!o)return t(null);var i=o.constructor;if(i===r.Object)return o===r.Object.prototype?{}:t(o);if(~e.call(i).indexOf("[native code]"))try{return new i}catch(e){}return t(o)},d=function(e,t,n,r){var o=y(e,t);for(var f in r.set(e,o),e)a.call(e,f)&&(o[f]=n(e[f],r));if(s)for(var u=i(e),l=0,p=u.length,d=void 0;l<p;++l)d=u[l],c.call(e,d)&&(o[d]=n(e[d],r));return o},h=function(e,t,f,u){var a=y(e,t);u.set(e,a);for(var c=s?o(e).concat(i(e)):o(e),l=0,p=c.length,d=void 0,h=void 0;l<p;++l)if("callee"!==(d=c[l])&&"caller"!==d)if(h=r(e,d)){h.get||h.set||(h.value=f(e[d],u));try{n(a,d,h)}catch(e){a[d]=h.value}}else a[d]=f(e[d],u);return a},b=Array.isArray,g=Object.getPrototypeOf,v=function(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:(console&&console.error&&console.error('Unable to locate global object, returning "this".'),this)}();function O(e,t){var n=!(!t||!t.isStrict),r=t&&t.realm||v,o=n?h:d,i=function(e,t){if(!e||"object"!=typeof e)return e;if(t.has(e))return t.get(e);var f,u,a,c=e.__proto__||g(e),s=c&&c.constructor;if(!s||s===r.Object)return o(e,r,i,t);if(b(e)){if(n)return h(e,r,i,t);f=new s,t.set(e,f);for(var l=0,p=e.length;l<p;++l)f[l]=i(e[l],t);return f}if(e instanceof r.Date)return new s(e.getTime());if(e instanceof r.RegExp)return(f=new s(e.source,e.flags||(a="",(u=e).global&&(a+="g"),u.ignoreCase&&(a+="i"),u.multiline&&(a+="m"),u.unicode&&(a+="u"),u.sticky&&(a+="y"),a))).lastIndex=e.lastIndex,f;if(r.Map&&e instanceof r.Map)return f=new s,t.set(e,f),e.forEach((function(e,n){f.set(n,i(e,t))})),f;if(r.Set&&e instanceof r.Set)return f=new s,t.set(e,f),e.forEach((function(e){f.add(i(e,t))})),f;if(r.Blob&&e instanceof r.Blob)return e.slice(0,e.size,e.type);if(r.Buffer&&r.Buffer.isBuffer(e))return f=r.Buffer.allocUnsafe?r.Buffer.allocUnsafe(e.length):new s(e.length),t.set(e,f),e.copy(f),f;if(r.ArrayBuffer){if(r.ArrayBuffer.isView(e))return f=new s(e.buffer.slice(0)),t.set(e,f),f;if(e instanceof r.ArrayBuffer)return f=e.slice(0),t.set(e,f),f}return"function"==typeof e.then||e instanceof Error||r.WeakMap&&e instanceof r.WeakMap||r.WeakSet&&e instanceof r.WeakSet?e:o(e,r,i,t)};return i(e,p())}return O.default=O,O.strict=function(e,t){return O(e,{isStrict:!0,realm:t?t.realm:void 0})},O}));
declare namespace FastCopy {
// @ts-ignore
export type Realm = Window | Global;
export type Realm = Record<string, any>;
export interface Cache {
_keys?: any[];
_values?: any[];
add: (value: any) => void;
has: (value: any) => boolean;
set: (key: any, value: any) => void;
get: (key: any) => any;
}
export type Copier = (object: any, cache: Cache) => any;
export type Copier = <Value = any>(value: Value, cache: Cache) => Value;
export type ObjectCloner = (object: any, realm: Realm, handleCopy: Copier, cache: Cache) => any;
export type ObjectCloner = <Value>(
object: Value,
realm: Realm,
handleCopy: Copier,
cache: Cache,
) => Value;

@@ -21,14 +27,14 @@ export type Options = {

declare function copy<ObjectType extends any = any>(
object: ObjectType,
declare function copy<Value = any>(
value: Value,
options?: FastCopy.Options,
): ObjectType;
): Value;
declare namespace copy {
function strictCopy<ObjectType extends any = any>(
object: ObjectType,
function strictCopy<Value = any>(
value: Value,
options?: FastCopy.Options,
): ObjectType;
): Value;
}
export default copy;

@@ -12,33 +12,36 @@ {

"devDependencies": {
"@types/jest": "^26.0.0",
"@types/lodash": "^4.14.155",
"@types/node": "^14.0.13",
"@types/ramda": "^0.27.6",
"@types/react": "^16.9.38",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-typescript": "^8.3.1",
"@types/eslint": "^8.4.1",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.181",
"@types/node": "^17.0.23",
"@types/ramda": "^0.28.7",
"@types/react": "^17.0.43",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
"benchee": "^1.0.3",
"cli-table2": "^0.2.0",
"cli-table3": "^0.6.1",
"clone": "^2.1.2",
"deepclone": "^1.0.2",
"eslint": "^8.12.0",
"eslint-webpack-plugin": "^3.1.1",
"fast-clone": "^1.5.3",
"html-webpack-plugin": "^4.3.0",
"html-webpack-plugin": "^5.5.0",
"in-publish": "^2.0.1",
"jest": "^26.0.1",
"jest": "^27.5.1",
"lodash": "^4.17.11",
"nyc": "^15.1.0",
"ramda": "^0.27.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"rollup": "^2.17.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^6.1.0",
"rollup-plugin-typescript2": "^0.27.1",
"ts-jest": "^26.1.0",
"ts-loader": "^7.0.5",
"tslint": "^6.1.2",
"tslint-config-airbnb": "^5.11.2",
"tslint-loader": "^3.5.4",
"typescript": "^3.9.5",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0"
"ramda": "^0.28.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"release-it": "^14.14.0",
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.1.4",
"ts-loader": "^9.2.8",
"typescript": "^4.6.3",
"webpack": "^5.71.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.8.1"
},

@@ -64,5 +67,5 @@ "homepage": "https://github.com/planttheidea/fast-copy#readme",

"clean": "rimraf dist",
"dev": "NODE_ENV=development webpack-dev-server --colors --progress --config=webpack/webpack.config.js",
"dev": "NODE_ENV=development webpack-dev-server --config=webpack/webpack.config.js",
"dist": "npm run clean && npm run build",
"lint": "NODE_ENV=test tslint 'src/*.ts'",
"lint": "eslint 'src/*.ts'",
"lint:fix": "npm run lint -- --fix",

@@ -80,3 +83,3 @@ "prepublishOnly": "npm run lint && npm run typecheck && npm run test && npm run dist",

"types": "index.d.ts",
"version": "2.1.1"
"version": "2.1.2"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc