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 1.2.2 to 1.2.3

4

CHANGELOG.md
# fast-copy CHANGELOG
## 1.2.3
- Support custom prototype applied to plain object via `Object.create()`
## 1.2.2

@@ -4,0 +8,0 @@

93

dist/fast-copy.js

@@ -11,20 +11,19 @@ (function (global, factory) {

var HAS_FLAGS_SUPPORT = typeof /foo/g.flags === 'string';
/**
* @constant {boolean} HAS_PROPERTY_SYMBOL_SUPPORT
*/
var HAS_PROPERTY_SYMBOL_SUPPORT = typeof global.Object.getOwnPropertySymbols === 'function';
/**
* @constant {boolean} HAS_WEAKSET_SUPPORT
*/
var HAS_WEAKSET_SUPPORT = typeof global.WeakSet === 'function';
// constants
var create = Object.create,
getKeys = Object.keys,
getSymbols = Object.getOwnPropertySymbols;
getSymbols = Object.getOwnPropertySymbols,
getPrototypeOf = Object.getPrototypeOf;
var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
/**

@@ -50,4 +49,42 @@ * @function getNewCache

};
/**
* @function getPrototype
*
* @description
* get the prototype of the object passed, using __proto__ when supported and
* falling back to getPrototypeOf
*
* @param {any} object the object to get the prototype of
* @returns {Object} the object's prototype
*/
var getPrototype = function () {
try {
throw new Error();
} catch (error) {
return getPrototypeOf;
}
}();
/**
* @function getObjectToCopy
*
* @description
* get the object to copy, including appropriate prototype
*
* @param {Object} object the object to copy
* @param {any} realm the realm to base the object prototype on
* @param {boolean} isPlainObject is the object a plain object
* @returns {Object} an empty version of the object to copy
*/
var getObjectToCopy = function getObjectToCopy(object, realm, isPlainObject) {
if (isPlainObject) {
var prototype = getPrototype(object);
return prototype === realm.Object.prototype ? {} : create(prototype);
}
return object.constructor ? new object.constructor() : create(null);
};
/**
* @function getRegExpFlags

@@ -61,2 +98,3 @@ *

*/
var getRegExpFlags = function getRegExpFlags(regExp) {

@@ -87,3 +125,2 @@ var flags = '';

};
/**

@@ -99,6 +136,6 @@ * @function isObjectCopyable

*/
var isObjectCopyable = function isObjectCopyable(object, cache) {
return typeof object === 'object' && object !== null && !cache.has(object);
};
/**

@@ -114,6 +151,6 @@ * @function shouldObjectBeCopied

*/
var shouldObjectBeCopied = function shouldObjectBeCopied(object, realm) {
return typeof object.then !== 'function' && !(object instanceof realm.Error) && !(realm.WeakMap && object instanceof realm.WeakMap) && !(realm.WeakSet && object instanceof realm.WeakSet);
};
/**

@@ -130,2 +167,3 @@ * @function copyArray

*/
var copyArray = function copyArray(array, copy, realm) {

@@ -140,3 +178,2 @@ var newArray = new array.constructor();

};
/**

@@ -151,6 +188,6 @@ * @function copyArrayBuffer

*/
var copyArrayBuffer = function copyArrayBuffer(arrayBuffer) {
return arrayBuffer.slice(0);
};
/**

@@ -166,10 +203,8 @@ * @function copyBuffer

*/
var copyBuffer = function copyBuffer(buffer, realm) {
var newBuffer = realm.Buffer.allocUnsafe ? realm.Buffer.allocUnsafe(buffer.length) : new realm.Buffer(buffer.length);
buffer.copy(newBuffer);
return newBuffer;
};
/**

@@ -184,12 +219,10 @@ * @function copyIterable

*/
var createCopyIterable = function createCopyIterable(assignmentHandler) {
return function (iterable, copy, realm) {
var newIterable = new iterable.constructor();
iterable.forEach(assignmentHandler(newIterable, copy, realm));
return newIterable;
};
};
var copyMap = createCopyIterable(function (iterable, copy, realm) {

@@ -205,3 +238,2 @@ return function (value, key) {

});
/**

@@ -219,12 +251,12 @@ * @function copyObject

*/
var copyObject = function copyObject(object, copy, realm, isPlainObject) {
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : create(null);
var newObject = getObjectToCopy(object, realm, isPlainObject);
var keys = getKeys(object);
if (keys.length) {
var key = void 0;
var key;
for (var index = 0; index < keys.length; index++) {
key = keys[index];
newObject[key] = copy(object[key], realm);

@@ -238,3 +270,3 @@ }

if (symbols.length) {
var symbol = void 0;
var symbol;

@@ -253,3 +285,2 @@ for (var _index = 0; _index < symbols.length; _index++) {

};
/**

@@ -265,10 +296,8 @@ * @function copyRegExp

*/
var copyRegExp = function copyRegExp(regExp, realm) {
var newRegExp = new realm.RegExp(regExp.source, HAS_FLAGS_SUPPORT ? regExp.flags : getRegExpFlags(regExp));
newRegExp.lastIndex = regExp.lastIndex;
return newRegExp;
};
/**

@@ -283,2 +312,3 @@ * @function copyTypedArray

*/
var copyTypedArray = function copyTypedArray(typedArray) {

@@ -289,3 +319,2 @@ return new typedArray.constructor(copyArrayBuffer(typedArray.buffer));

// utils
/**

@@ -301,5 +330,8 @@ * @function copy

*/
function copy(object) {
var realm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : global;
function copy(object, realm) {
if (realm === void 0) {
realm = global;
}
var cache = getNewCache();

@@ -314,3 +346,2 @@

cache.add(object);
return copyArray(object, handleCopy, realm);

@@ -321,3 +352,2 @@ }

cache.add(object);
return copyObject(object, handleCopy, realm, true);

@@ -336,3 +366,2 @@ }

cache.add(object);
return copyMap(object, handleCopy, realm);

@@ -343,3 +372,2 @@ }

cache.add(object);
return copySet(object, handleCopy, realm);

@@ -364,3 +392,2 @@ }

cache.add(object);
return copyObject(object, handleCopy, realm);

@@ -367,0 +394,0 @@ }

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.fastCopy={})}(this,function(e){"use strict";var b="string"==typeof/foo/g.flags,l="function"==typeof global.Object.getOwnPropertySymbols,t="function"==typeof global.WeakSet,d=Object.create,p=Object.keys,y=Object.getOwnPropertySymbols,g=Object.prototype.propertyIsEnumerable,h=function(e){return e.slice(0)},n=function(f){return function(e,t,n){var r=new e.constructor;return e.forEach(f(r,t,n)),r}},v=n(function(n,r,f){return function(e,t){return n.set(t,r(e,f))}}),w=n(function(t,n,r){return function(e){return t.add(n(e,r))}}),O=function(e,t,n,r){var f=r?{}:e.constructor?new e.constructor:d(null),o=p(e);if(o.length)for(var u=void 0,a=0;a<o.length;a++)f[u=o[a]]=t(e[u],n);if(l){var i=y(e);if(i.length)for(var c=void 0,s=0;s<i.length;s++)c=i[s],g.call(e,c)&&(f[c]=t(e[c],n))}return f};e.default=function(e){var y=1<arguments.length&&void 0!==arguments[1]?arguments[1]:global,g=t?new WeakSet:d({_values:[],add:function(e){this._values.push(e)},has:function(e){return!!~this._values.indexOf(e)}});return function e(t){if(r=g,"object"!=typeof(n=t)||null===n||r.has(n))return t;var n,r,f,o,u,a,i,c,s,l,d,p;if(Array.isArray(t))return g.add(t),function(e,t,n){for(var r=new e.constructor,f=0;f<e.length;f++)r[f]=t(e[f],n);return r}(t,e,y);if(t.constructor===y.Object)return g.add(t),O(t,e,y,!0);if(t instanceof y.Date)return new Date(t.getTime());if(t instanceof y.RegExp)return f=t,(a=new y.RegExp(f.source,b?f.flags:(u="",(o=f).global&&(u+="g"),o.ignoreCase&&(u+="i"),o.multiline&&(u+="m"),o.unicode&&(u+="u"),o.sticky&&(u+="y"),u))).lastIndex=f.lastIndex,a;if(y.Map&&t instanceof y.Map)return g.add(t),v(t,e,y);if(y.Set&&t instanceof y.Set)return g.add(t),w(t,e,y);if(y.Buffer&&y.Buffer.isBuffer(t))return i=t,s=(c=y).Buffer.allocUnsafe?c.Buffer.allocUnsafe(i.length):new c.Buffer(i.length),i.copy(s),s;if(y.ArrayBuffer){if(y.ArrayBuffer.isView(t))return new(l=t).constructor(h(l.buffer));if(t instanceof y.ArrayBuffer)return h(t)}return p=y,"function"==typeof(d=t).then||d instanceof p.Error||p.WeakMap&&d instanceof p.WeakMap||p.WeakSet&&d instanceof p.WeakSet?t:(g.add(t),O(t,e,y))}(e)},Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.fastCopy={})}(this,function(e){"use strict";var b="string"==typeof/foo/g.flags,l="function"==typeof global.Object.getOwnPropertySymbols,t="function"==typeof global.WeakSet,p=Object.create,d=Object.keys,y=Object.getOwnPropertySymbols,n=Object.getPrototypeOf,g=Object.prototype.propertyIsEnumerable,h=function(){try{throw new Error}catch(e){return n}}(),v=function(e){return e.slice(0)},r=function(f){return function(e,t,n){var r=new e.constructor;return e.forEach(f(r,t,n)),r}},w=r(function(n,r,f){return function(e,t){return n.set(t,r(e,f))}}),O=r(function(t,n,r){return function(e){return t.add(n(e,r))}}),j=function(e,t,n,r){var f=function(e,t,n){if(n){var r=h(e);return r===t.Object.prototype?{}:p(r)}return e.constructor?new e.constructor:p(null)}(e,n,r),o=d(e);if(o.length)for(var u,a=0;a<o.length;a++)f[u=o[a]]=t(e[u],n);if(l){var i=y(e);if(i.length)for(var c,s=0;s<i.length;s++)c=i[s],g.call(e,c)&&(f[c]=t(e[c],n))}return f};e.default=function(e,y){void 0===y&&(y=global);var g=t?new WeakSet:p({_values:[],add:function(e){this._values.push(e)},has:function(e){return!!~this._values.indexOf(e)}});return function e(t){if(r=g,"object"!=typeof(n=t)||null===n||r.has(n))return t;var n,r,f,o,u,a,i,c,s,l,p,d;if(Array.isArray(t))return g.add(t),function(e,t,n){for(var r=new e.constructor,f=0;f<e.length;f++)r[f]=t(e[f],n);return r}(t,e,y);if(t.constructor===y.Object)return g.add(t),j(t,e,y,!0);if(t instanceof y.Date)return new Date(t.getTime());if(t instanceof y.RegExp)return f=t,(a=new y.RegExp(f.source,b?f.flags:(u="",(o=f).global&&(u+="g"),o.ignoreCase&&(u+="i"),o.multiline&&(u+="m"),o.unicode&&(u+="u"),o.sticky&&(u+="y"),u))).lastIndex=f.lastIndex,a;if(y.Map&&t instanceof y.Map)return g.add(t),w(t,e,y);if(y.Set&&t instanceof y.Set)return g.add(t),O(t,e,y);if(y.Buffer&&y.Buffer.isBuffer(t))return i=t,s=(c=y).Buffer.allocUnsafe?c.Buffer.allocUnsafe(i.length):new c.Buffer(i.length),i.copy(s),s;if(y.ArrayBuffer){if(y.ArrayBuffer.isView(t))return new(l=t).constructor(v(l.buffer));if(t instanceof y.ArrayBuffer)return v(t)}return d=y,"function"==typeof(p=t).then||p instanceof d.Error||d.WeakMap&&p instanceof d.WeakMap||d.WeakSet&&p instanceof d.WeakSet?t:(g.add(t),j(t,e,y))}(e)},Object.defineProperty(e,"__esModule",{value:!0})});

@@ -5,11 +5,11 @@ /**

export var HAS_FLAGS_SUPPORT = typeof /foo/g.flags === 'string';
/**
* @constant {boolean} HAS_PROPERTY_SYMBOL_SUPPORT
*/
export var HAS_PROPERTY_SYMBOL_SUPPORT = typeof global.Object.getOwnPropertySymbols === 'function';
/**
* @constant {boolean} HAS_WEAKSET_SUPPORT
*/
export var HAS_WEAKSET_SUPPORT = typeof global.WeakSet === 'function';
// utils
import { copyArray, copyArrayBuffer, copyBuffer, copyMap, copyObject, copyRegExp, copySet, copyTypedArray, getNewCache, isObjectCopyable, shouldObjectBeCopied } from './utils';
/**

@@ -14,5 +13,8 @@ * @function copy

*/
export default function copy(object) {
var realm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : global;
export default function copy(object, realm) {
if (realm === void 0) {
realm = global;
}
var cache = getNewCache();

@@ -27,3 +29,2 @@

cache.add(object);
return copyArray(object, handleCopy, realm);

@@ -34,3 +35,2 @@ }

cache.add(object);
return copyObject(object, handleCopy, realm, true);

@@ -49,3 +49,2 @@ }

cache.add(object);
return copyMap(object, handleCopy, realm);

@@ -56,3 +55,2 @@ }

cache.add(object);
return copySet(object, handleCopy, realm);

@@ -77,3 +75,2 @@ }

cache.add(object);
return copyObject(object, handleCopy, realm);

@@ -80,0 +77,0 @@ }

// constants
import { HAS_FLAGS_SUPPORT, HAS_PROPERTY_SYMBOL_SUPPORT, HAS_WEAKSET_SUPPORT } from './constants';
var create = Object.create,
getKeys = Object.keys,
getSymbols = Object.getOwnPropertySymbols;
getSymbols = Object.getOwnPropertySymbols,
getPrototypeOf = Object.getPrototypeOf;
var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
/**

@@ -29,4 +28,60 @@ * @function getNewCache

};
/**
* @function getProto
*
* @description
* get the __proto__ prototype property from the object
*
* @param {any} object the object to get the __proto__ from
* @returns {Object} tthe prototype of the object
*/
export var getProto = function getProto(object) {
return object ? object.__proto__ : null;
};
/**
* @function getPrototype
*
* @description
* get the prototype of the object passed, using __proto__ when supported and
* falling back to getPrototypeOf
*
* @param {any} object the object to get the prototype of
* @returns {Object} the object's prototype
*/
export var getPrototype = function () {
try {
var object = {};
if (object.__proto__ !== void 0) {
return getProto;
}
throw new Error();
} catch (error) {
return getPrototypeOf;
}
}();
/**
* @function getObjectToCopy
*
* @description
* get the object to copy, including appropriate prototype
*
* @param {Object} object the object to copy
* @param {any} realm the realm to base the object prototype on
* @param {boolean} isPlainObject is the object a plain object
* @returns {Object} an empty version of the object to copy
*/
export var getObjectToCopy = function getObjectToCopy(object, realm, isPlainObject) {
if (isPlainObject) {
var prototype = getPrototype(object);
return prototype === realm.Object.prototype ? {} : create(prototype);
}
return object.constructor ? new object.constructor() : create(null);
};
/**
* @function getRegExpFlags

@@ -40,2 +95,3 @@ *

*/
export var getRegExpFlags = function getRegExpFlags(regExp) {

@@ -66,3 +122,2 @@ var flags = '';

};
/**

@@ -78,6 +133,6 @@ * @function isObjectCopyable

*/
export var isObjectCopyable = function isObjectCopyable(object, cache) {
return typeof object === 'object' && object !== null && !cache.has(object);
};
/**

@@ -93,6 +148,6 @@ * @function shouldObjectBeCopied

*/
export var shouldObjectBeCopied = function shouldObjectBeCopied(object, realm) {
return typeof object.then !== 'function' && !(object instanceof realm.Error) && !(realm.WeakMap && object instanceof realm.WeakMap) && !(realm.WeakSet && object instanceof realm.WeakSet);
};
/**

@@ -109,2 +164,3 @@ * @function copyArray

*/
export var copyArray = function copyArray(array, copy, realm) {

@@ -119,3 +175,2 @@ var newArray = new array.constructor();

};
/**

@@ -130,6 +185,6 @@ * @function copyArrayBuffer

*/
export var copyArrayBuffer = function copyArrayBuffer(arrayBuffer) {
return arrayBuffer.slice(0);
};
/**

@@ -145,10 +200,8 @@ * @function copyBuffer

*/
export var copyBuffer = function copyBuffer(buffer, realm) {
var newBuffer = realm.Buffer.allocUnsafe ? realm.Buffer.allocUnsafe(buffer.length) : new realm.Buffer(buffer.length);
buffer.copy(newBuffer);
return newBuffer;
};
/**

@@ -163,12 +216,10 @@ * @function copyIterable

*/
export var createCopyIterable = function createCopyIterable(assignmentHandler) {
return function (iterable, copy, realm) {
var newIterable = new iterable.constructor();
iterable.forEach(assignmentHandler(newIterable, copy, realm));
return newIterable;
};
};
export var copyMap = createCopyIterable(function (iterable, copy, realm) {

@@ -184,3 +235,2 @@ return function (value, key) {

});
/**

@@ -198,12 +248,12 @@ * @function copyObject

*/
export var copyObject = function copyObject(object, copy, realm, isPlainObject) {
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : create(null);
var newObject = getObjectToCopy(object, realm, isPlainObject);
var keys = getKeys(object);
if (keys.length) {
var key = void 0;
var key;
for (var index = 0; index < keys.length; index++) {
key = keys[index];
newObject[key] = copy(object[key], realm);

@@ -217,3 +267,3 @@ }

if (symbols.length) {
var symbol = void 0;
var symbol;

@@ -232,3 +282,2 @@ for (var _index = 0; _index < symbols.length; _index++) {

};
/**

@@ -244,10 +293,8 @@ * @function copyRegExp

*/
export var copyRegExp = function copyRegExp(regExp, realm) {
var newRegExp = new realm.RegExp(regExp.source, HAS_FLAGS_SUPPORT ? regExp.flags : getRegExpFlags(regExp));
newRegExp.lastIndex = regExp.lastIndex;
return newRegExp;
};
/**

@@ -262,4 +309,5 @@ * @function copyTypedArray

*/
export var copyTypedArray = function copyTypedArray(typedArray) {
return new typedArray.constructor(copyArrayBuffer(typedArray.buffer));
};

@@ -1,17 +0,22 @@

'use strict';
"use strict";
exports.__esModule = true;
exports.HAS_WEAKSET_SUPPORT = exports.HAS_PROPERTY_SYMBOL_SUPPORT = exports.HAS_FLAGS_SUPPORT = void 0;
/**
* @constant {boolean} HAS_FLAGS_SUPPORT
*/
var HAS_FLAGS_SUPPORT = exports.HAS_FLAGS_SUPPORT = typeof /foo/g.flags === 'string';
var HAS_FLAGS_SUPPORT = typeof /foo/g.flags === 'string';
/**
* @constant {boolean} HAS_PROPERTY_SYMBOL_SUPPORT
*/
var HAS_PROPERTY_SYMBOL_SUPPORT = exports.HAS_PROPERTY_SYMBOL_SUPPORT = typeof global.Object.getOwnPropertySymbols === 'function';
exports.HAS_FLAGS_SUPPORT = HAS_FLAGS_SUPPORT;
var HAS_PROPERTY_SYMBOL_SUPPORT = typeof global.Object.getOwnPropertySymbols === 'function';
/**
* @constant {boolean} HAS_WEAKSET_SUPPORT
*/
var HAS_WEAKSET_SUPPORT = exports.HAS_WEAKSET_SUPPORT = typeof global.WeakSet === 'function';
exports.HAS_PROPERTY_SYMBOL_SUPPORT = HAS_PROPERTY_SYMBOL_SUPPORT;
var HAS_WEAKSET_SUPPORT = typeof global.WeakSet === 'function';
exports.HAS_WEAKSET_SUPPORT = HAS_WEAKSET_SUPPORT;

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

'use strict';
"use strict";

@@ -6,4 +6,6 @@ exports.__esModule = true;

var _utils = require('./utils');
var _utils = require("./utils");
// utils
/**

@@ -19,4 +21,6 @@ * @function copy

*/
function copy(object) {
var realm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : global;
function copy(object, realm) {
if (realm === void 0) {
realm = global;
}

@@ -32,3 +36,2 @@ var cache = (0, _utils.getNewCache)();

cache.add(object);
return (0, _utils.copyArray)(object, handleCopy, realm);

@@ -39,3 +42,2 @@ }

cache.add(object);
return (0, _utils.copyObject)(object, handleCopy, realm, true);

@@ -54,3 +56,2 @@ }

cache.add(object);
return (0, _utils.copyMap)(object, handleCopy, realm);

@@ -61,3 +62,2 @@ }

cache.add(object);
return (0, _utils.copySet)(object, handleCopy, realm);

@@ -82,3 +82,2 @@ }

cache.add(object);
return (0, _utils.copyObject)(object, handleCopy, realm);

@@ -91,2 +90,2 @@ }

return handleCopy(object);
} // utils
}

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

'use strict';
"use strict";
exports.__esModule = true;
exports.copyTypedArray = exports.copyRegExp = exports.copyObject = exports.copySet = exports.copyMap = exports.createCopyIterable = exports.copyBuffer = exports.copyArrayBuffer = exports.copyArray = exports.shouldObjectBeCopied = exports.isObjectCopyable = exports.getRegExpFlags = exports.getNewCache = undefined;
exports.copyTypedArray = exports.copyRegExp = exports.copyObject = exports.copySet = exports.copyMap = exports.createCopyIterable = exports.copyBuffer = exports.copyArrayBuffer = exports.copyArray = exports.shouldObjectBeCopied = exports.isObjectCopyable = exports.getRegExpFlags = exports.getObjectToCopy = exports.getPrototype = exports.getProto = exports.getNewCache = void 0;
var _constants = require('./constants');
var _constants = require("./constants");
// constants
var create = Object.create,
getKeys = Object.keys,
getSymbols = Object.getOwnPropertySymbols; // constants
getSymbols = Object.getOwnPropertySymbols,
getPrototypeOf = Object.getPrototypeOf;
var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
/**

@@ -23,3 +23,3 @@ * @function getNewCache

var getNewCache = exports.getNewCache = function getNewCache() {
var getNewCache = function getNewCache() {
return _constants.HAS_WEAKSET_SUPPORT ? new WeakSet() : create({

@@ -35,4 +35,69 @@ _values: [],

};
/**
* @function getProto
*
* @description
* get the __proto__ prototype property from the object
*
* @param {any} object the object to get the __proto__ from
* @returns {Object} tthe prototype of the object
*/
exports.getNewCache = getNewCache;
var getProto = function getProto(object) {
return object ? object.__proto__ : null;
};
/**
* @function getPrototype
*
* @description
* get the prototype of the object passed, using __proto__ when supported and
* falling back to getPrototypeOf
*
* @param {any} object the object to get the prototype of
* @returns {Object} the object's prototype
*/
exports.getProto = getProto;
var getPrototype = function () {
try {
var object = {};
if (object.__proto__ !== void 0) {
return getProto;
}
throw new Error();
} catch (error) {
return getPrototypeOf;
}
}();
/**
* @function getObjectToCopy
*
* @description
* get the object to copy, including appropriate prototype
*
* @param {Object} object the object to copy
* @param {any} realm the realm to base the object prototype on
* @param {boolean} isPlainObject is the object a plain object
* @returns {Object} an empty version of the object to copy
*/
exports.getPrototype = getPrototype;
var getObjectToCopy = function getObjectToCopy(object, realm, isPlainObject) {
if (isPlainObject) {
var prototype = getPrototype(object);
return prototype === realm.Object.prototype ? {} : create(prototype);
}
return object.constructor ? new object.constructor() : create(null);
};
/**
* @function getRegExpFlags

@@ -46,3 +111,7 @@ *

*/
var getRegExpFlags = exports.getRegExpFlags = function getRegExpFlags(regExp) {
exports.getObjectToCopy = getObjectToCopy;
var getRegExpFlags = function getRegExpFlags(regExp) {
var flags = '';

@@ -72,3 +141,2 @@

};
/**

@@ -84,6 +152,9 @@ * @function isObjectCopyable

*/
var isObjectCopyable = exports.isObjectCopyable = function isObjectCopyable(object, cache) {
exports.getRegExpFlags = getRegExpFlags;
var isObjectCopyable = function isObjectCopyable(object, cache) {
return typeof object === 'object' && object !== null && !cache.has(object);
};
/**

@@ -99,6 +170,9 @@ * @function shouldObjectBeCopied

*/
var shouldObjectBeCopied = exports.shouldObjectBeCopied = function shouldObjectBeCopied(object, realm) {
exports.isObjectCopyable = isObjectCopyable;
var shouldObjectBeCopied = function shouldObjectBeCopied(object, realm) {
return typeof object.then !== 'function' && !(object instanceof realm.Error) && !(realm.WeakMap && object instanceof realm.WeakMap) && !(realm.WeakSet && object instanceof realm.WeakSet);
};
/**

@@ -115,3 +189,7 @@ * @function copyArray

*/
var copyArray = exports.copyArray = function copyArray(array, copy, realm) {
exports.shouldObjectBeCopied = shouldObjectBeCopied;
var copyArray = function copyArray(array, copy, realm) {
var newArray = new array.constructor();

@@ -125,3 +203,2 @@

};
/**

@@ -136,6 +213,9 @@ * @function copyArrayBuffer

*/
var copyArrayBuffer = exports.copyArrayBuffer = function copyArrayBuffer(arrayBuffer) {
exports.copyArray = copyArray;
var copyArrayBuffer = function copyArrayBuffer(arrayBuffer) {
return arrayBuffer.slice(0);
};
/**

@@ -151,10 +231,11 @@ * @function copyBuffer

*/
var copyBuffer = exports.copyBuffer = function copyBuffer(buffer, realm) {
exports.copyArrayBuffer = copyArrayBuffer;
var copyBuffer = function copyBuffer(buffer, realm) {
var newBuffer = realm.Buffer.allocUnsafe ? realm.Buffer.allocUnsafe(buffer.length) : new realm.Buffer(buffer.length);
buffer.copy(newBuffer);
return newBuffer;
};
/**

@@ -169,8 +250,10 @@ * @function copyIterable

*/
var createCopyIterable = exports.createCopyIterable = function createCopyIterable(assignmentHandler) {
exports.copyBuffer = copyBuffer;
var createCopyIterable = function createCopyIterable(assignmentHandler) {
return function (iterable, copy, realm) {
var newIterable = new iterable.constructor();
iterable.forEach(assignmentHandler(newIterable, copy, realm));
return newIterable;

@@ -180,3 +263,4 @@ };

var copyMap = exports.copyMap = createCopyIterable(function (iterable, copy, realm) {
exports.createCopyIterable = createCopyIterable;
var copyMap = createCopyIterable(function (iterable, copy, realm) {
return function (value, key) {

@@ -186,3 +270,4 @@ return iterable.set(key, copy(value, realm));

});
var copySet = exports.copySet = createCopyIterable(function (iterable, copy, realm) {
exports.copyMap = copyMap;
var copySet = createCopyIterable(function (iterable, copy, realm) {
return function (value) {

@@ -192,3 +277,2 @@ return iterable.add(copy(value, realm));

});
/**

@@ -206,12 +290,14 @@ * @function copyObject

*/
var copyObject = exports.copyObject = function copyObject(object, copy, realm, isPlainObject) {
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : create(null);
exports.copySet = copySet;
var copyObject = function copyObject(object, copy, realm, isPlainObject) {
var newObject = getObjectToCopy(object, realm, isPlainObject);
var keys = getKeys(object);
if (keys.length) {
var key = void 0;
var key;
for (var index = 0; index < keys.length; index++) {
key = keys[index];
newObject[key] = copy(object[key], realm);

@@ -225,3 +311,3 @@ }

if (symbols.length) {
var symbol = void 0;
var symbol;

@@ -240,3 +326,2 @@ for (var _index = 0; _index < symbols.length; _index++) {

};
/**

@@ -252,10 +337,11 @@ * @function copyRegExp

*/
var copyRegExp = exports.copyRegExp = function copyRegExp(regExp, realm) {
exports.copyObject = copyObject;
var copyRegExp = function copyRegExp(regExp, realm) {
var newRegExp = new realm.RegExp(regExp.source, _constants.HAS_FLAGS_SUPPORT ? regExp.flags : getRegExpFlags(regExp));
newRegExp.lastIndex = regExp.lastIndex;
return newRegExp;
};
/**

@@ -270,4 +356,10 @@ * @function copyTypedArray

*/
var copyTypedArray = exports.copyTypedArray = function copyTypedArray(typedArray) {
exports.copyRegExp = copyRegExp;
var copyTypedArray = function copyTypedArray(typedArray) {
return new typedArray.constructor(copyArrayBuffer(typedArray.buffer));
};
};
exports.copyTypedArray = copyTypedArray;
{
"author": "tony_quetano@planttheidea.com",
"ava": {
"babel": "inherit",
"failFast": true,

@@ -10,5 +9,5 @@ "files": [

"require": [
"babel-register"
"@babel/register"
],
"source": [
"sources": [
"src/*.js"

@@ -23,12 +22,12 @@ ],

"devDependencies": {
"ava": "^0.25.0",
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.5",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.26.0",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"ava": "^1.0.0-beta.8",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.0",
"benchmark": "^2.1.4",
"clone": "^2.1.1",
"clone": "^2.1.2",
"decircularize": "^1.0.0",

@@ -39,29 +38,29 @@ "deep-clone": "^3.0.3",

"deepclone": "^1.0.2",
"eslint": "^5.1.0",
"eslint-config-rapid7": "^3.0.3",
"eslint": "^5.7.0",
"eslint-config-rapid7": "^3.1.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.0.0",
"eslint-loader": "^2.1.1",
"fast-clone": "^1.5.3",
"fast-deep-equal": "^2.0.1",
"fast-deepclone": "^1.0.0",
"fast-equals": "^1.5.3",
"fast-equals": "^1.6.1",
"html-webpack-plugin": "^3.2.0",
"in-publish": "^2.0.0",
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"nano-equal": "^2.0.2",
"nyc": "^12.0.2",
"nyc": "^13.1.0",
"optimize-js-plugin": "^0.0.4",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-fast-compare": "^2.0.1",
"rollup": "^0.62.0",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-uglify": "^4.0.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-fast-compare": "^2.0.2",
"rollup": "^0.66.6",
"rollup-plugin-babel": "^4.0.1",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-uglify": "^6.0.0",
"shallow-equal-fuzzy": "^0.0.2",
"sinon": "^6.1.3",
"sinon": "^7.0.0",
"underscore": "^1.9.1",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4"
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9"
},

@@ -104,3 +103,3 @@ "homepage": "https://github.com/planttheidea/fast-copy#readme",

"types": "index.d.ts",
"version": "1.2.2"
"version": "1.2.3"
}

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