Comparing version 1.2.1 to 1.2.2
# fast-copy CHANGELOG | ||
## 1.2.2 | ||
- Support copy of extensions of native `Array` with alternative `push()` method | ||
## 1.2.1 | ||
* Under-the-hood optimizations per recommendations from #7 | ||
- Under-the-hood optimizations per recommendations from #7 | ||
## 1.2.0 | ||
* Add support for multiple realms | ||
- Add support for multiple realms | ||
## 1.1.2 | ||
* Optimize order of operations for common use cases | ||
- Optimize order of operations for common use cases | ||
## 1.1.1 | ||
* Fix cache using `WeakSet` when there was support for `WeakMap`s instead of `WeakSet`s (in case one was polyfilled but not the other) | ||
- Fix cache using `WeakSet` when there was support for `WeakMap`s instead of `WeakSet`s (in case one was polyfilled but not the other) | ||
## 1.1.0 | ||
* Add TypeScript and FlowType bindings | ||
- Add TypeScript and FlowType bindings | ||
## 1.0.1 | ||
* Activate tree-shaking | ||
- Activate tree-shaking | ||
## 1.0.0 | ||
* Initial release | ||
- Initial release |
@@ -24,2 +24,5 @@ (function (global, factory) { | ||
var create = Object.create, | ||
getKeys = Object.keys, | ||
getSymbols = Object.getOwnPropertySymbols; | ||
var propertyIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
@@ -35,4 +38,5 @@ | ||
*/ | ||
var getNewCache = function getNewCache() { | ||
return HAS_WEAKSET_SUPPORT ? new WeakSet() : Object.create({ | ||
return HAS_WEAKSET_SUPPORT ? new WeakSet() : create({ | ||
_values: [], | ||
@@ -126,3 +130,3 @@ add: function add(value) { | ||
for (var index = 0; index < array.length; index++) { | ||
newArray.push(copy(array[index], realm)); | ||
newArray[index] = copy(array[index], realm); | ||
} | ||
@@ -143,3 +147,3 @@ | ||
var copyArrayBuffer = function copyArrayBuffer(arrayBuffer) { | ||
return arrayBuffer.slice(); | ||
return arrayBuffer.slice(0); | ||
}; | ||
@@ -208,4 +212,4 @@ | ||
var copyObject = function copyObject(object, copy, realm, isPlainObject) { | ||
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : Object.create(null); | ||
var keys = Object.keys(object); | ||
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : create(null); | ||
var keys = getKeys(object); | ||
@@ -223,3 +227,3 @@ if (keys.length) { | ||
if (HAS_PROPERTY_SYMBOL_SUPPORT) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
var symbols = getSymbols(object); | ||
@@ -290,3 +294,3 @@ if (symbols.length) { | ||
function handleCopy(object) { | ||
var handleCopy = function handleCopy(object) { | ||
if (!isObjectCopyable(object, cache)) { | ||
@@ -349,3 +353,3 @@ return object; | ||
return object; | ||
} | ||
}; | ||
@@ -352,0 +356,0 @@ return handleCopy(object); |
@@ -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="string"==typeof/foo/g.flags,t="function"==typeof global.Object.getOwnPropertySymbols,r="function"==typeof global.WeakSet,f=Object.prototype.propertyIsEnumerable,o=function(){return r?new WeakSet:Object.create({_values:[],add:function(e){this._values.push(e)},has:function(e){return!!~this._values.indexOf(e)}})},u=function(e,n){return"object"==typeof e&&null!==e&&!n.has(e)},i=function(e,n){return!("function"==typeof e.then||e instanceof n.Error||n.WeakMap&&e instanceof n.WeakMap||n.WeakSet&&e instanceof n.WeakSet)},a=function(e,n,t){for(var r=new e.constructor,f=0;f<e.length;f++)r.push(n(e[f],t));return r},c=function(e){return e.slice()},s=function(e,n){var t=n.Buffer.allocUnsafe?n.Buffer.allocUnsafe(e.length):new n.Buffer(e.length);return e.copy(t),t},l=function(e){return function(n,t,r){var f=new n.constructor;return n.forEach(e(f,t,r)),f}},d=l(function(e,n,t){return function(r,f){return e.set(f,n(r,t))}}),p=l(function(e,n,t){return function(r){return e.add(n(r,t))}}),y=function(e,n,r,o){var u=o?{}:e.constructor?new e.constructor:Object.create(null),i=Object.keys(e);if(i.length)for(var a=void 0,c=0;c<i.length;c++)u[a=i[c]]=n(e[a],r);if(t){var s=Object.getOwnPropertySymbols(e);if(s.length)for(var l=void 0,d=0;d<s.length;d++)l=s[d],f.call(e,l)&&(u[l]=n(e[l],r))}return u},g=function(e,t){var r=new t.RegExp(e.source,n?e.flags:function(e){var n="";return e.global&&(n+="g"),e.ignoreCase&&(n+="i"),e.multiline&&(n+="m"),e.unicode&&(n+="u"),e.sticky&&(n+="y"),n}(e));return r.lastIndex=e.lastIndex,r},b=function(e){return new e.constructor(c(e.buffer))};e.default=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:global,t=o();return function e(r){if(!u(r,t))return r;if(Array.isArray(r))return t.add(r),a(r,e,n);if(r.constructor===n.Object)return t.add(r),y(r,e,n,!0);if(r instanceof n.Date)return new Date(r.getTime());if(r instanceof n.RegExp)return g(r,n);if(n.Map&&r instanceof n.Map)return t.add(r),d(r,e,n);if(n.Set&&r instanceof n.Set)return t.add(r),p(r,e,n);if(n.Buffer&&n.Buffer.isBuffer(r))return s(r,n);if(n.ArrayBuffer){if(n.ArrayBuffer.isView(r))return b(r);if(r instanceof n.ArrayBuffer)return c(r)}return i(r,n)?(t.add(r),y(r,e,n)):r}(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,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})}); |
@@ -19,3 +19,3 @@ // utils | ||
function handleCopy(object) { | ||
var handleCopy = function handleCopy(object) { | ||
if (!isObjectCopyable(object, cache)) { | ||
@@ -78,5 +78,5 @@ return object; | ||
return object; | ||
} | ||
}; | ||
return handleCopy(object); | ||
} |
// constants | ||
import { HAS_FLAGS_SUPPORT, HAS_PROPERTY_SYMBOL_SUPPORT, HAS_WEAKSET_SUPPORT } from './constants'; | ||
var create = Object.create, | ||
getKeys = Object.keys, | ||
getSymbols = Object.getOwnPropertySymbols; | ||
var propertyIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
@@ -14,4 +17,5 @@ | ||
*/ | ||
export var getNewCache = function getNewCache() { | ||
return HAS_WEAKSET_SUPPORT ? new WeakSet() : Object.create({ | ||
return HAS_WEAKSET_SUPPORT ? new WeakSet() : create({ | ||
_values: [], | ||
@@ -105,3 +109,3 @@ add: function add(value) { | ||
for (var index = 0; index < array.length; index++) { | ||
newArray.push(copy(array[index], realm)); | ||
newArray[index] = copy(array[index], realm); | ||
} | ||
@@ -122,3 +126,3 @@ | ||
export var copyArrayBuffer = function copyArrayBuffer(arrayBuffer) { | ||
return arrayBuffer.slice(); | ||
return arrayBuffer.slice(0); | ||
}; | ||
@@ -187,4 +191,4 @@ | ||
export var copyObject = function copyObject(object, copy, realm, isPlainObject) { | ||
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : Object.create(null); | ||
var keys = Object.keys(object); | ||
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : create(null); | ||
var keys = getKeys(object); | ||
@@ -202,3 +206,3 @@ if (keys.length) { | ||
if (HAS_PROPERTY_SYMBOL_SUPPORT) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
var symbols = getSymbols(object); | ||
@@ -205,0 +209,0 @@ if (symbols.length) { |
@@ -23,3 +23,3 @@ 'use strict'; | ||
function handleCopy(object) { | ||
var handleCopy = function handleCopy(object) { | ||
if (!(0, _utils.isObjectCopyable)(object, cache)) { | ||
@@ -82,5 +82,5 @@ return object; | ||
return object; | ||
} | ||
}; | ||
return handleCopy(object); | ||
} // utils |
@@ -8,2 +8,6 @@ 'use strict'; | ||
var create = Object.create, | ||
getKeys = Object.keys, | ||
getSymbols = Object.getOwnPropertySymbols; // constants | ||
var propertyIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
@@ -19,5 +23,5 @@ | ||
*/ | ||
// constants | ||
var getNewCache = exports.getNewCache = function getNewCache() { | ||
return _constants.HAS_WEAKSET_SUPPORT ? new WeakSet() : Object.create({ | ||
return _constants.HAS_WEAKSET_SUPPORT ? new WeakSet() : create({ | ||
_values: [], | ||
@@ -111,3 +115,3 @@ add: function add(value) { | ||
for (var index = 0; index < array.length; index++) { | ||
newArray.push(copy(array[index], realm)); | ||
newArray[index] = copy(array[index], realm); | ||
} | ||
@@ -128,3 +132,3 @@ | ||
var copyArrayBuffer = exports.copyArrayBuffer = function copyArrayBuffer(arrayBuffer) { | ||
return arrayBuffer.slice(); | ||
return arrayBuffer.slice(0); | ||
}; | ||
@@ -193,4 +197,4 @@ | ||
var copyObject = exports.copyObject = function copyObject(object, copy, realm, isPlainObject) { | ||
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : Object.create(null); | ||
var keys = Object.keys(object); | ||
var newObject = isPlainObject ? {} : object.constructor ? new object.constructor() : create(null); | ||
var keys = getKeys(object); | ||
@@ -208,3 +212,3 @@ if (keys.length) { | ||
if (_constants.HAS_PROPERTY_SYMBOL_SUPPORT) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
var symbols = getSymbols(object); | ||
@@ -211,0 +215,0 @@ if (symbols.length) { |
@@ -24,4 +24,4 @@ { | ||
"babel-cli": "^6.26.0", | ||
"babel-eslint": "^8.2.3", | ||
"babel-loader": "^7.1.4", | ||
"babel-eslint": "^8.2.5", | ||
"babel-loader": "^7.1.5", | ||
"babel-preset-env": "^1.6.1", | ||
@@ -38,4 +38,4 @@ "babel-preset-react": "^6.24.1", | ||
"deepclone": "^1.0.2", | ||
"eslint": "^4.19.1", | ||
"eslint-config-rapid7": "^2.11.1", | ||
"eslint": "^5.1.0", | ||
"eslint-config-rapid7": "^3.0.3", | ||
"eslint-friendly-formatter": "^4.0.1", | ||
@@ -46,3 +46,3 @@ "eslint-loader": "^2.0.0", | ||
"fast-deepclone": "^1.0.0", | ||
"fast-equals": "^1.4.1", | ||
"fast-equals": "^1.5.3", | ||
"html-webpack-plugin": "^3.2.0", | ||
@@ -52,16 +52,16 @@ "in-publish": "^2.0.0", | ||
"nano-equal": "^2.0.2", | ||
"nyc": "^11.7.3", | ||
"nyc": "^12.0.2", | ||
"optimize-js-plugin": "^0.0.4", | ||
"react": "^16.3.2", | ||
"react-dom": "^16.3.2", | ||
"react-fast-compare": "^1.0.0", | ||
"rollup": "^0.58.2", | ||
"rollup-plugin-babel": "^3.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": "^3.0.0", | ||
"rollup-plugin-uglify": "^4.0.0", | ||
"shallow-equal-fuzzy": "^0.0.2", | ||
"sinon": "^5.0.7", | ||
"underscore": "^1.9.0", | ||
"webpack": "^4.8.1", | ||
"webpack-cli": "^2.1.3", | ||
"sinon": "^6.1.3", | ||
"underscore": "^1.9.1", | ||
"webpack": "^4.15.1", | ||
"webpack-cli": "^3.0.8", | ||
"webpack-dev-server": "^3.1.4" | ||
@@ -105,3 +105,3 @@ }, | ||
"types": "index.d.ts", | ||
"version": "1.2.1" | ||
"version": "1.2.2" | ||
} |
118
README.md
@@ -11,11 +11,11 @@ # fast-copy | ||
* [Usage](#usage) | ||
* [Multiple realms](#multiple-realms) | ||
* [Types supported](#types-supported) | ||
* [Benchmarks](#benchmarks) | ||
* [Simple objects](#simple-objects) | ||
* [Complex objects](#complex-objects) | ||
* [Circular objects](#circular-objects) | ||
* [Special objects](#special-objects) | ||
* [Development](#development) | ||
- [Usage](#usage) | ||
- [Multiple realms](#multiple-realms) | ||
- [Types supported](#types-supported) | ||
- [Benchmarks](#benchmarks) | ||
- [Simple objects](#simple-objects) | ||
- [Complex objects](#complex-objects) | ||
- [Circular objects](#circular-objects) | ||
- [Special objects](#special-objects) | ||
- [Development](#development) | ||
@@ -58,38 +58,38 @@ ## Usage | ||
* `Array` | ||
* `ArrayBuffer` | ||
* `Buffer` | ||
* `DataView` | ||
* `Date` | ||
* `Float32Array` | ||
* `Float64Array` | ||
* `Int8Array` | ||
* `Int16Array` | ||
* `Int32Array` | ||
* `Map` | ||
* `Object` | ||
* `RegExp` | ||
* `Set` | ||
* `Uint8Array` | ||
* `Uint8ClampedArray` | ||
* `Uint16Array` | ||
* `Uint32Array` | ||
* `React` components | ||
* Custom constructors | ||
- `Array` | ||
- `ArrayBuffer` | ||
- `Buffer` | ||
- `DataView` | ||
- `Date` | ||
- `Float32Array` | ||
- `Float64Array` | ||
- `Int8Array` | ||
- `Int16Array` | ||
- `Int32Array` | ||
- `Map` | ||
- `Object` | ||
- `RegExp` | ||
- `Set` | ||
- `Uint8Array` | ||
- `Uint8ClampedArray` | ||
- `Uint16Array` | ||
- `Uint32Array` | ||
- `React` components | ||
- Custom constructors | ||
The following object types are copied directly, as they are either primitives, cannot be cloned, or the common use-case implementation does not expect cloning: | ||
* `AsyncFunction` | ||
* `Boolean` | ||
* `Error` | ||
* `Function` | ||
* `GeneratorFunction` | ||
* `Number` | ||
* `Null` | ||
* `Promise` | ||
* `String` | ||
* `Symbol` | ||
* `Undefined` | ||
* `WeakMap` | ||
* `WeakSet` | ||
- `AsyncFunction` | ||
- `Boolean` | ||
- `Error` | ||
- `Function` | ||
- `GeneratorFunction` | ||
- `Number` | ||
- `Null` | ||
- `Promise` | ||
- `String` | ||
- `Symbol` | ||
- `Undefined` | ||
- `WeakMap` | ||
- `WeakSet` | ||
@@ -156,18 +156,18 @@ Circular objects are supported out of the box as well. By default a cache based on `WeakSet` is used, but if `WeakSet` is not available then a standard `Object` fallback is used. The benchmarks quoted below are based on use of `WeakSet`. | ||
* benchmark => run benchmark tests against other equality libraries | ||
* build => build dist files with `rollup` | ||
* clean => run `clean:dist`, `clean:es`, and `clean:lib` scripts | ||
* clean:dist => run `rimraf` on the `dist` folder | ||
* clean:es => run `rimraf` on the `es` folder | ||
* clean:lib => run `rimraf` on the `lib` folder | ||
* dev => start webpack playground App | ||
* dist => run `build` and `build:minified` scripts | ||
* lint => run ESLint on all files in `src` folder (also runs on `dev` script) | ||
* lint:fix => run `lint` script, but with auto-fixer | ||
* prepublish:compile => run `lint`, `test:coverage`, `transpile:lib`, `transpile:es`, and `dist` scripts | ||
* start => run `dev` | ||
* test => run AVA with NODE_ENV=test on all files in `test` folder | ||
* test:coverage => run same script as `test` with code coverage calculation via `nyc` | ||
* test:watch => run same script as `test` but keep persistent watcher | ||
* transpile:es => run Babel on all files in `src` folder (transpiled to `es` folder without transpilation of ES2015 export syntax) | ||
* transpile:lib => run Babel on all files in `src` folder (transpiled to `lib` folder) | ||
- benchmark => run benchmark tests against other equality libraries | ||
- build => build dist files with `rollup` | ||
- clean => run `clean:dist`, `clean:es`, and `clean:lib` scripts | ||
- clean:dist => run `rimraf` on the `dist` folder | ||
- clean:es => run `rimraf` on the `es` folder | ||
- clean:lib => run `rimraf` on the `lib` folder | ||
- dev => start webpack playground App | ||
- dist => run `build` and `build:minified` scripts | ||
- lint => run ESLint on all files in `src` folder (also runs on `dev` script) | ||
- lint:fix => run `lint` script, but with auto-fixer | ||
- prepublish:compile => run `lint`, `test:coverage`, `transpile:lib`, `transpile:es`, and `dist` scripts | ||
- start => run `dev` | ||
- test => run AVA with NODE_ENV=test on all files in `test` folder | ||
- test:coverage => run same script as `test` with code coverage calculation via `nyc` | ||
- test:watch => run same script as `test` but keep persistent watcher | ||
- transpile:es => run Babel on all files in `src` folder (transpiled to `es` folder without transpilation of ES2015 export syntax) | ||
- transpile:lib => run Babel on all files in `src` folder (transpiled to `lib` folder) |
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
56795
15
876