Comparing version 1.1.1 to 1.1.2
# fast-copy CHANGELOG | ||
## 1.1.2 | ||
* Optimize order of operations for common use cases | ||
## 1.1.1 | ||
@@ -4,0 +8,0 @@ |
@@ -118,6 +118,19 @@ (function (global, factory) { | ||
var isObjectCopyable = function isObjectCopyable(object, cache) { | ||
return typeof object === 'object' && !!object && !cache.has(object) && typeof object.then !== 'function' && !(object instanceof Error) && !(HAS_WEAKMAP_SUPPORT && object instanceof WeakMap) && !(HAS_WEAKSET_SUPPORT && object instanceof WeakSet); | ||
return typeof object === 'object' && object !== null && !cache.has(object); | ||
}; | ||
/** | ||
* @function shouldObjectBeCopied | ||
* | ||
* @description | ||
* should the object be copied | ||
* | ||
* @param {any} object the object to test | ||
* @returns {boolean} should the object be copied | ||
*/ | ||
var shouldObjectBeCopied = function shouldObjectBeCopied(object) { | ||
return typeof object.then !== 'function' && !(object instanceof Error) && !(HAS_WEAKMAP_SUPPORT && object instanceof WeakMap) && !(HAS_WEAKSET_SUPPORT && object instanceof WeakSet); | ||
}; | ||
/** | ||
* @function copyArray | ||
@@ -306,2 +319,14 @@ * | ||
if (HAS_MAP_SUPPORT && object instanceof Map) { | ||
cache.add(object); | ||
return copyIterable(object, handleCopy, true); | ||
} | ||
if (HAS_SET_SUPPORT && object instanceof Set) { | ||
cache.add(object); | ||
return copyIterable(object, handleCopy, false); | ||
} | ||
if (HAS_BUFFER_SUPPORT && Buffer.isBuffer(object)) { | ||
@@ -321,13 +346,9 @@ return copyBuffer(object); | ||
cache.add(object); | ||
if (shouldObjectBeCopied(object)) { | ||
cache.add(object); | ||
if (HAS_MAP_SUPPORT && object instanceof Map) { | ||
return copyIterable(object, handleCopy, true); | ||
return copyObject(object, handleCopy); | ||
} | ||
if (HAS_SET_SUPPORT && object instanceof Set) { | ||
return copyIterable(object, handleCopy, false); | ||
} | ||
return copyObject(object, handleCopy, false); | ||
return object; | ||
} | ||
@@ -334,0 +355,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.fastCopy={})}(this,function(e){"use strict";var n="function"==typeof ArrayBuffer,t="function"==typeof Buffer,r="function"==typeof Map,f="function"==typeof Object.getOwnPropertySymbols,o="function"==typeof Set,u="function"==typeof WeakMap,i="function"==typeof WeakSet,c=Object.prototype.propertyIsEnumerable,a=function(){return i?new WeakSet:Object.create({_values:[],add:function(e){this._values.push(e)},has:function(e){return!!~this._values.indexOf(e)}})},s=function(e,n){return!("object"!=typeof e||!e||n.has(e)||"function"==typeof e.then||e instanceof Error||u&&e instanceof WeakMap||i&&e instanceof WeakSet)},l=function(e,n){for(var t=new e.constructor,r=0;r<e.length;r++)t.push(n(e[r]));return t},p=function(e){return e.slice()},y=function(e){var n=Buffer.allocUnsafe?Buffer.allocUnsafe(e.length):new Buffer(e.length);return e.copy(n),n},d=function(e,n,t){var r=new e.constructor;return e.forEach(function(e,f){t?r.set(f,n(e)):r.add(n(e))}),r},v=function(e,n,t){var r=t?{}:e.constructor?new e.constructor:Object.create(null),o=Object.keys(e);if(o.length)for(var u=void 0,i=0;i<o.length;i++)r[u=o[i]]=n(e[u]);var a=function(e){return f?Object.getOwnPropertySymbols(e).filter(function(n){return c.call(e,n)}):[]}(e);if(a.length)for(var s=void 0,l=0;l<a.length;l++)r[s=a[l]]=n(e[s]);return r},h=function(e){var n=new RegExp(e.source,function(e){var n="";return e.global&&(n+="g"),e.ignoreCase&&(n+="i"),e.multiline&&(n+="m"),n}(e));return n.lastIndex=e.lastIndex,n},b=function(e){return new e.constructor(e.buffer)};e.default=function(e){var f=a();return function e(u){if(!s(u,f))return u;if(Array.isArray(u))return f.add(u),l(u,e);if(u.constructor===Object)return f.add(u),v(u,e,!0);if(u instanceof Date)return new Date(u.getTime());if(u instanceof RegExp)return h(u);if(t&&Buffer.isBuffer(u))return y(u);if(n){if(ArrayBuffer.isView(u))return b(u);if(u instanceof ArrayBuffer)return p(u)}return f.add(u),r&&u instanceof Map?d(u,e,!0):o&&u instanceof Set?d(u,e,!1):v(u,e,!1)}(e)},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.fastCopy={})}(this,function(e){"use strict";var n="function"==typeof ArrayBuffer,t="function"==typeof Buffer,r="function"==typeof Map,f="function"==typeof Object.getOwnPropertySymbols,o="function"==typeof Set,u="function"==typeof WeakMap,i="function"==typeof WeakSet,c=Object.prototype.propertyIsEnumerable,a=function(){return i?new WeakSet:Object.create({_values:[],add:function(e){this._values.push(e)},has:function(e){return!!~this._values.indexOf(e)}})},s=function(e,n){return"object"==typeof e&&null!==e&&!n.has(e)},l=function(e){return!("function"==typeof e.then||e instanceof Error||u&&e instanceof WeakMap||i&&e instanceof WeakSet)},p=function(e,n){for(var t=new e.constructor,r=0;r<e.length;r++)t.push(n(e[r]));return t},d=function(e){return e.slice()},y=function(e){var n=Buffer.allocUnsafe?Buffer.allocUnsafe(e.length):new Buffer(e.length);return e.copy(n),n},v=function(e,n,t){var r=new e.constructor;return e.forEach(function(e,f){t?r.set(f,n(e)):r.add(n(e))}),r},h=function(e,n,t){var r=t?{}:e.constructor?new e.constructor:Object.create(null),o=Object.keys(e);if(o.length)for(var u=void 0,i=0;i<o.length;i++)r[u=o[i]]=n(e[u]);var a=function(e){return f?Object.getOwnPropertySymbols(e).filter(function(n){return c.call(e,n)}):[]}(e);if(a.length)for(var s=void 0,l=0;l<a.length;l++)r[s=a[l]]=n(e[s]);return r},b=function(e){var n=new RegExp(e.source,function(e){var n="";return e.global&&(n+="g"),e.ignoreCase&&(n+="i"),e.multiline&&(n+="m"),n}(e));return n.lastIndex=e.lastIndex,n},g=function(e){return new e.constructor(e.buffer)};e.default=function(e){var f=a();return function e(u){if(!s(u,f))return u;if(Array.isArray(u))return f.add(u),p(u,e);if(u.constructor===Object)return f.add(u),h(u,e,!0);if(u instanceof Date)return new Date(u.getTime());if(u instanceof RegExp)return b(u);if(r&&u instanceof Map)return f.add(u),v(u,e,!0);if(o&&u instanceof Set)return f.add(u),v(u,e,!1);if(t&&Buffer.isBuffer(u))return y(u);if(n){if(ArrayBuffer.isView(u))return g(u);if(u instanceof ArrayBuffer)return d(u)}return l(u)?(f.add(u),h(u,e)):u}(e)},Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -5,3 +5,3 @@ // constants | ||
// utils | ||
import { copyArray, copyArrayBuffer, copyBuffer, copyIterable, copyObject, copyRegExp, copyTypedArray, getNewCache, isObjectCopyable } from './utils'; | ||
import { copyArray, copyArrayBuffer, copyBuffer, copyIterable, copyObject, copyRegExp, copyTypedArray, getNewCache, isObjectCopyable, shouldObjectBeCopied } from './utils'; | ||
@@ -45,2 +45,14 @@ /** | ||
if (HAS_MAP_SUPPORT && object instanceof Map) { | ||
cache.add(object); | ||
return copyIterable(object, handleCopy, true); | ||
} | ||
if (HAS_SET_SUPPORT && object instanceof Set) { | ||
cache.add(object); | ||
return copyIterable(object, handleCopy, false); | ||
} | ||
if (HAS_BUFFER_SUPPORT && Buffer.isBuffer(object)) { | ||
@@ -60,13 +72,9 @@ return copyBuffer(object); | ||
cache.add(object); | ||
if (shouldObjectBeCopied(object)) { | ||
cache.add(object); | ||
if (HAS_MAP_SUPPORT && object instanceof Map) { | ||
return copyIterable(object, handleCopy, true); | ||
return copyObject(object, handleCopy); | ||
} | ||
if (HAS_SET_SUPPORT && object instanceof Set) { | ||
return copyIterable(object, handleCopy, false); | ||
} | ||
return copyObject(object, handleCopy, false); | ||
return object; | ||
} | ||
@@ -73,0 +81,0 @@ |
@@ -79,6 +79,19 @@ // constants | ||
export var isObjectCopyable = function isObjectCopyable(object, cache) { | ||
return typeof object === 'object' && !!object && !cache.has(object) && typeof object.then !== 'function' && !(object instanceof Error) && !(HAS_WEAKMAP_SUPPORT && object instanceof WeakMap) && !(HAS_WEAKSET_SUPPORT && object instanceof WeakSet); | ||
return typeof object === 'object' && object !== null && !cache.has(object); | ||
}; | ||
/** | ||
* @function shouldObjectBeCopied | ||
* | ||
* @description | ||
* should the object be copied | ||
* | ||
* @param {any} object the object to test | ||
* @returns {boolean} should the object be copied | ||
*/ | ||
export var shouldObjectBeCopied = function shouldObjectBeCopied(object) { | ||
return typeof object.then !== 'function' && !(object instanceof Error) && !(HAS_WEAKMAP_SUPPORT && object instanceof WeakMap) && !(HAS_WEAKSET_SUPPORT && object instanceof WeakSet); | ||
}; | ||
/** | ||
* @function copyArray | ||
@@ -85,0 +98,0 @@ * |
@@ -48,2 +48,14 @@ 'use strict'; | ||
if (_constants.HAS_MAP_SUPPORT && object instanceof Map) { | ||
cache.add(object); | ||
return (0, _utils.copyIterable)(object, handleCopy, true); | ||
} | ||
if (_constants.HAS_SET_SUPPORT && object instanceof Set) { | ||
cache.add(object); | ||
return (0, _utils.copyIterable)(object, handleCopy, false); | ||
} | ||
if (_constants.HAS_BUFFER_SUPPORT && Buffer.isBuffer(object)) { | ||
@@ -63,13 +75,9 @@ return (0, _utils.copyBuffer)(object); | ||
cache.add(object); | ||
if ((0, _utils.shouldObjectBeCopied)(object)) { | ||
cache.add(object); | ||
if (_constants.HAS_MAP_SUPPORT && object instanceof Map) { | ||
return (0, _utils.copyIterable)(object, handleCopy, true); | ||
return (0, _utils.copyObject)(object, handleCopy); | ||
} | ||
if (_constants.HAS_SET_SUPPORT && object instanceof Set) { | ||
return (0, _utils.copyIterable)(object, handleCopy, false); | ||
} | ||
return (0, _utils.copyObject)(object, handleCopy, false); | ||
return object; | ||
} | ||
@@ -76,0 +84,0 @@ |
'use strict'; | ||
exports.__esModule = true; | ||
exports.copyTypedArray = exports.copyRegExp = exports.copyObject = exports.copyIterable = exports.copyBuffer = exports.copyArrayBuffer = exports.copyArray = exports.isObjectCopyable = exports.getSymbols = exports.getRegExpFlags = exports.getNewCache = undefined; | ||
exports.copyTypedArray = exports.copyRegExp = exports.copyObject = exports.copyIterable = exports.copyBuffer = exports.copyArrayBuffer = exports.copyArray = exports.shouldObjectBeCopied = exports.isObjectCopyable = exports.getSymbols = exports.getRegExpFlags = exports.getNewCache = undefined; | ||
@@ -84,6 +84,19 @@ var _constants = require('./constants'); | ||
var isObjectCopyable = exports.isObjectCopyable = function isObjectCopyable(object, cache) { | ||
return typeof object === 'object' && !!object && !cache.has(object) && typeof object.then !== 'function' && !(object instanceof Error) && !(_constants.HAS_WEAKMAP_SUPPORT && object instanceof WeakMap) && !(_constants.HAS_WEAKSET_SUPPORT && object instanceof WeakSet); | ||
return typeof object === 'object' && object !== null && !cache.has(object); | ||
}; | ||
/** | ||
* @function shouldObjectBeCopied | ||
* | ||
* @description | ||
* should the object be copied | ||
* | ||
* @param {any} object the object to test | ||
* @returns {boolean} should the object be copied | ||
*/ | ||
var shouldObjectBeCopied = exports.shouldObjectBeCopied = function shouldObjectBeCopied(object) { | ||
return typeof object.then !== 'function' && !(object instanceof Error) && !(_constants.HAS_WEAKMAP_SUPPORT && object instanceof WeakMap) && !(_constants.HAS_WEAKSET_SUPPORT && object instanceof WeakSet); | ||
}; | ||
/** | ||
* @function copyArray | ||
@@ -90,0 +103,0 @@ * |
@@ -101,3 +101,3 @@ { | ||
"types": "index.d.ts", | ||
"version": "1.1.1" | ||
"version": "1.1.2" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
352621
951