{"author":{"name":"tony_quetano@planttheidea.com"},"contributors":[{"name":"Dariusz Rzepka","email":"rzepkadarek@gmail.com"}],"browser":"dist/umd/index.js","bugs":{"url":"https://github.com/planttheidea/fast-copy/issues"},"description":"A blazing fast deep object copier","devDependencies":{"@rollup/plugin-node-resolve":"^14.1.0","@rollup/plugin-typescript":"^8.5.0","@types/eslint":"^8.4.6","@types/jest":"^29.1.0","@types/lodash":"^4.14.186","@types/node":"^18.7.23","@types/ramda":"^0.28.15","@types/react":"^18.0.21","@typescript-eslint/eslint-plugin":"^5.38.1","@typescript-eslint/parser":"^5.38.1","benchee":"^1.0.3","cli-table3":"^0.6.3","clone":"^2.1.2","deepclone":"^1.0.2","eslint":"^8.24.0","eslint-webpack-plugin":"^3.2.0","fast-clone":"^1.5.3","html-webpack-plugin":"^5.5.0","in-publish":"^2.0.1","jest":"^29.1.1","lodash":"^4.17.11","nyc":"^15.1.0","ramda":"^0.28.0","react":"^18.2.0","react-dom":"^18.2.0","release-it":"15.4.1","rollup":"^2.79.1","rollup-plugin-terser":"^7.0.2","ts-jest":"^29.0.3","ts-loader":"^9.4.1","typescript":"^4.8.4","webpack":"^5.74.0","webpack-cli":"^4.10.0","webpack-dev-server":"^4.11.1"},"exports":{".":{"import":{"types":"./dist/esm/types/index.d.ts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/types/index.d.ts","default":"./dist/cjs/index.cjs"},"default":{"types":"./dist/umd/types/index.d.ts","default":"./dist/umd/index.js"}}},"homepage":"https://github.com/planttheidea/fast-copy#readme","keywords":["clone","deep","copy","fast"],"license":"MIT","main":"dist/cjs/index.cjs","module":"dist/esm/index.mjs","name":"fast-copy","repository":{"type":"git","url":"git+https://github.com/planttheidea/fast-copy.git"},"scripts":{"benchmark":"npm run clean && npm run build:cjs && node benchmark/index.cjs","build":"npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:min","build:cjs":"NODE_ENV=production rollup -c rollup/config.cjs.js && tsc -p ./tsconfig/cjs.json","build:esm":"NODE_ENV=production rollup -c rollup/config.esm.js && tsc -p ./tsconfig/esm.json","build:min":"NODE_ENV=production rollup -c rollup/config.min.js && tsc -p ./tsconfig/min.json","build:umd":"NODE_ENV=production rollup -c rollup/config.umd.js && tsc -p ./tsconfig/umd.json","clean":"rimraf dist","dev":"NODE_ENV=development webpack-dev-server --config=webpack/webpack.config.js","dist":"npm run clean && npm run build","lint":"eslint 'src/*.ts' '__tests__/*.ts' 'DEV_ONLY/*.ts'","lint:fix":"npm run lint -- --fix","prepublishOnly":"npm run lint && npm run typecheck && npm run test && npm run dist","release":"release-it","release:beta":"release-it --config=.release-it.beta.json","release:dry":"release-it --dry-run","start":"npm run dev","test":"NODE_PATH=. jest","test:coverage":"npm run test -- --coverage","test:watch":"npm run test -- --watch","typecheck":"tsc --noEmit"},"type":"module","types":"index.d.ts","version":"3.0.0-beta.8","readme":"# fast-copy\n\n<img src=\"https://img.shields.io/badge/build-passing-brightgreen.svg\"/>\n<img src=\"https://img.shields.io/badge/coverage-100%25-brightgreen.svg\"/>\n<img src=\"https://img.shields.io/badge/license-MIT-blue.svg\"/>\n\nA [blazing fast](#benchmarks) deep object copier\n\n## Table of contents\n\n- [fast-copy](#fast-copy)\n  - [Table of contents](#table-of-contents)\n  - [Usage](#usage)\n  - [API](#api)\n    - [`copy`](#copy)\n    - [`copyStrict`](#copystrict)\n    - [`createCopier`](#createcopier)\n      - [Copier state](#copier-state)\n        - [`cache`](#cache)\n        - [`copier`](#copier)\n        - [`Constructor` / `prototype`](#constructor--prototype)\n    - [`createStrictCopier`](#createstrictcopier)\n      - [Copier methods](#copier-methods)\n  - [Types supported](#types-supported)\n  - [Aspects of copying](#aspects-of-copying)\n    - [Error references are copied over (instead of creating a new `*Error` object)](#error-references-are-copied-over-instead-of-creating-a-new-error-object)\n    - [The constructor of the original object is used, instead of using known globals.](#the-constructor-of-the-original-object-is-used-instead-of-using-known-globals)\n  - [Benchmarks](#benchmarks)\n      - [Simple objects](#simple-objects)\n      - [Complex objects](#complex-objects)\n      - [Big data](#big-data)\n      - [Circular objects](#circular-objects)\n      - [Special objects](#special-objects)\n  - [Development](#development)\n\n## Usage\n\n```javascript\nimport { copy } from 'fast-copy';\nimport { deepEqual } from 'fast-equals';\n\nconst object = {\n  array: [123, { deep: 'value' }],\n  map: new Map([\n    ['foo', {}],\n    [{ bar: 'baz' }, 'quz'],\n  ]),\n};\n\nconst copiedObject = copy(object);\n\nconsole.log(copiedObject === object); // false\nconsole.log(deepEqual(copiedObject, object)); // true\n```\n\n## API\n\n### `copy`\n\nDeeply copy the object passed.\n\n```ts\nimport copy from 'fast-copy';\n\nconst copied = copy({ foo: 'bar' });\n```\n\n### `copyStrict`\n\nDeeply copy the object passed, but with additional strictness when replicating the original object:\n\n- Properties retain their original property descriptor\n- Non-enumerable keys are copied\n- Non-standard properties (e.g., keys on an `Array` object) are copied\n\n```ts\nimport { copyStrict } from 'fast-copy';\n\nconst object = { foo: 'bar' };\nobject.nonEnumerable = Object.defineProperty(object, 'bar', {\n  enumerable: false,\n  value: 'baz',\n});\n\nconst copied = copy(object);\n```\n\n**NOTE**: This method is significantly slower than [`copy`](#copy), so it is recommended to only use this when you have specific use-cases that require it.\n\n### `createCopier`\n\nCreate a custom copier based on the type-specific methods passed. This is useful if you want to squeeze out maximum performance, or perform something other than a standard deep copy.\n\n```ts\nimport { createCopier } from 'fast-copy';\n\nconst copyShallow = createCopier({\n  array: (array) => [...array],\n  map: (map) => new Map(map.entries()),\n  object: (object) => ({ ...object }),\n  set: (set) => new Set(set.values()),\n});\n```\n\nEach internal copier method has the following contract:\n\n```ts\ntype InternalCopier<Value> = (value: Value, state: State) => Value;\n\ninterface State {\n  Constructor: any;\n  cache: WeakMap;\n  copier: InternalCopier<any>;\n  prototype: any;\n}\n```\n\nAny method overriding the defaults must maintain this contract.\n\n#### Copier state\n\n##### `cache`\n\nIf you want to maintain circular reference handling, then you'll need the methods to handle cache population for future lookups:\n\n```ts\nfunction shallowlyCloneArray<Value extends any[]>(\n  value: Value,\n  state: State\n): Value {\n  const clone = [...value];\n\n  state.cache.set(value, clone);\n\n  return clone;\n}\n```\n\n##### `copier`\n\n`copier` is provided for recursive calls with deeply-nested objects.\n\n```ts\nfunction deeplyCloneArray<Value extends any[]>(\n  value: Value,\n  state: State\n): Value {\n  const clone = [];\n\n  state.cache.set(value, clone);\n\n  value.forEach((item) => state.copier(item, state));\n\n  return clone;\n}\n```\n\nNote above I am using `forEach` instead of a simple `map`. This is because it is highly recommended to store the clone in [`cache`](#cache) eagerly when deeply copying, so that nested circular references are handled correctly.\n\n##### `Constructor` / `prototype`\n\nBoth `Constructor` and `prototype` properties are only populated with complex objects that are not standard objects or arrays. This is mainly useful for custom subclasses of these globals, or maintaining custom prototypes of objects.\n\n```ts\nfunction deeplyCloneSubclassArray<Value extends CustomArray>(\n  value: Value,\n  state: State\n): Value {\n  const clone = new state.Constructor();\n\n  state.cache.set(value, clone);\n\n  value.forEach((item) => clone.push(item));\n\n  return clone;\n}\n\nfunction deeplyCloneCustomObject<Value extends CustomObject>(\n  value: Value,\n  state: State\n): Value {\n  const clone = Object.create(state.prototype);\n\n  state.cache.set(value, clone);\n\n  Object.entries(value).forEach(([k, v]) => (clone[k] = v));\n\n  return clone;\n}\n```\n\n### `createStrictCopier`\n\nCreate a custom copier based on the type-specific methods passed, but defaulting to the same functions normally used for `copyStrict`. This is useful if you want to squeeze out better performance while maintaining strict requirements, or perform something other than a strict deep copy.\n\n```ts\nconst createStrictClone = (value, clone) =>\n  Object.getOwnPropertyNames(value).reduce(\n    (clone, property) =>\n      Object.defineProperty(\n        clone,\n        property,\n        Object.getOwnPropertyDescriptor(value, property) || {\n          configurable: true,\n          enumerable: true,\n          value: clone[property],\n          writable: true,\n        }\n      ),\n    clone\n  );\n\nconst copyStrictShallow = createStrictCopier({\n  array: (array) => createStrictClone(array, []),\n  map: (map) => createStrictClone(map, new Map(map.entries())),\n  object: (object) => createStrictClone(object, {}),\n  set: (set) => createStrictClone(set, new Set(set.values())),\n});\n```\n\n**NOTE**: This method is significantly slower than [`copy`](#copy), so it is recommended to only use this when you have specific use-cases that require it.\n\n#### Copier methods\n\n- `array` => Array\n- `arrayBuffer`=> ArrayBuffer, Float32Array, Float64Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, Uint64Array\n- `blob` => Blob\n- `dataView` => DataView\n- `date` => Date\n- `error` => Error, AggregateError, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError\n- `map` => Map\n- `object` => Object, or any custom constructor\n- `regExp` => RegExp\n- `set` => Set\n\n## Types supported\n\nThe following object types are deeply cloned when they are either properties on the object passed, or the object itself:\n\n- `Array`\n- `ArrayBuffer`\n- `Blob`\n- `Buffer`\n- `DataView`\n- `Date`\n- `Float32Array`\n- `Float64Array`\n- `Int8Array`\n- `Int16Array`\n- `Int32Array`\n- `Map`\n- `Object`\n- `RegExp`\n- `Set`\n- `Uint8Array`\n- `Uint8ClampedArray`\n- `Uint16Array`\n- `Uint32Array`\n- `React` components\n- Custom constructors\n\nThe following object types are copied directly, as they are either primitives, cannot be cloned, or the common use-case implementation does not expect cloning:\n\n- `AsyncFunction`\n- `Boolean`\n- `Error`\n- `Function`\n- `GeneratorFunction`\n- `Number`\n- `Null`\n- `Promise`\n- `String`\n- `Symbol`\n- `Undefined`\n- `WeakMap`\n- `WeakSet`\n\nCircular objects are supported out of the box. By default, a cache based on `WeakSet` is used, but if `WeakSet` is not available then a fallback is used. The benchmarks quoted below are based on use of `WeakSet`.\n\n## Aspects of copying\n\nInherently, what is considered a valid copy is subjective because of different requirements and use-cases. For this library, some decisions were explicitly made.\n\n### Error references are copied over (instead of creating a new `*Error` object)\n\nWhile it would be relatively trivial to copy over the message and stack to a new object of the same `Error` subclass, it is a common practice to \"override\" the message or stack, and copies would not retain this mutation. As such, the original reference is copied.\n\n### The constructor of the original object is used, instead of using known globals.\n\nStarting in ES2015, native globals can be subclassed like any custom class. When copying, we explicitly reuse the constructor of the original object. However, the expectation is that these subclasses would have the same constructur signature as their native base class. This is a common community practice, however because there is the possibility of inaccuracy if the contract differs, it should be noted.\n\n## Benchmarks\n\n#### Simple objects\n\n_Small number of properties, all values are primitives_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **fast-copy**      | **5,880,312**       |\n| lodash.cloneDeep   | 2,706,261           |\n| clone              | 2,207,231           |\n| deepclone          | 1,274,810           |\n| fast-clone         | 1,239,952           |\n| ramda              | 1,146,152           |\n| fast-copy (strict) | 852,382             |\n\n#### Complex objects\n\n_Large number of properties, values are a combination of primitives and complex objects_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **fast-copy**      | **162,858**         |\n| ramda              | 142,104             |\n| deepclone          | 133,607             |\n| fast-clone         | 101,143             |\n| clone              | 70,872              |\n| fast-copy (strict) | 62,961              |\n| lodash.cloneDeep   | 62,060              |\n\n#### Big data\n\n_Very large number of properties with high amount of nesting, mainly objects and arrays_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **fast-copy**      | 303                 |\n| fast-clone         | 245                 |\n| deepclone          | 151                 |\n| lodash.cloneDeep   | 150                 |\n| clone              | 93                  |\n| fast-copy (strict) | 90                  |\n| ramda              | 42                  |\n\n#### Circular objects\n\n_Objects that deeply reference themselves_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **fast-copy**      | **2,420,466**       |\n| deepclone          | 1,386,896           |\n| ramda              | 1,024,108           |\n| lodash.cloneDeep   | 989,796             |\n| clone              | 987,721             |\n| fast-copy (strict) | 617,602             |\n| fast-clone         | 0 (not supported)   |\n\n#### Special objects\n\n_Custom constructors, React components, etc_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **fast-copy**      | **152,792**         |\n| clone              | 74,347              |\n| fast-clone         | 66,576              |\n| lodash.cloneDeep   | 64,760              |\n| ramda              | 53,542              |\n| deepclone          | 28,823              |\n| fast-copy (strict) | 21,362              |\n\n## Development\n\nStandard practice, clone the repo and `yarn` (or `npm i`) to get the dependencies. The following npm scripts are available:\n\n- benchmark => run benchmark tests against other equality libraries\n- build => run `build:esm`, `build:cjs`, `build:umd`, and `build:min` scripts\n- build:cjs => build CJS files and types\n- build:esm => build ESM files and types\n- build:min => build minified files and types\n- build:umd => build UMD files and types\n- clean => run `rimraf` on the `dist` folder\n- dev => start webpack playground App\n- dist => run `clean` and `build` scripts\n- lint => run ESLint on all files in `src` folder (also runs on `dev` script)\n- lint:fix => run `lint` script, but with auto-fixer\n- prepublishOnly => run `lint`, `test:coverage`, and `dist` scripts\n- release => run `prepublishOnly` and release with new version\n- release:beta => run `prepublishOnly` and release with new beta version\n- release:dry => run `prepublishOnly` and simulate a new release\n- start => run `dev`\n- test => run AVA with NODE_ENV=test on all files in `test` folder\n- test:coverage => run same script as `test` with code coverage calculation via `nyc`\n- test:watch => run same script as `test` but keep persistent watcher\n- typecheck => run `tsc` on the codebase\n","readmeFilename":"README.md","gitHead":"1dec6f645dc8c4236b45f3af8b550168c98dc256","_id":"fast-copy@3.0.0-beta.8","_nodeVersion":"16.14.2","_npmVersion":"8.7.0","dist":{"integrity":"sha512-kCE98w4x9EHRnjqcq0U98wfeNhLBCcVAeytGFc4KsuPT/dmzC/l8wHe3OpbFeHzA9aWW4MIR/ndkuLo/21cBlw==","shasum":"2d0afc1f520646db0592400eb7303bb4d9fee112","tarball":"http://registry-npm.ywwl.com/fast-copy/download/fast-copy-3.0.0-beta.8.tgz","fileCount":39,"unpackedSize":195299,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDg9DHssH3CJsMSfhWuY2ImJUyVYLaJTU9xqlu7CJrNewIgcAF6sBmI1nA5EfmKthEGYbRYIFQVPn0kyinzIuS4++k="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjOPeDACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqzYw/9FFlP9zhb7fTLhYKvmkoOLUbj3ChcAEunQliP6TPv7XuvQUUK\r\nMvu9UisZ9FA3IAKIDNHkOD9UiNAUSadXpnHZRnsOwclzCEvoE35/TUZ/s3vq\r\nGzxG6vmT/UEITg4WgBIkh8VpPP7bio1tUikHoEKR0R2LQ9r1BzDexmAQ183R\r\nlLsfyHq9kGaJbb/FfXOuE6fFTp5O2yooc/KYYteh+j8DBIxftrk3NzXMsvHS\r\nAw2bwnM+A9wE6iLXndfMd2o/WLUKKfYrJ951hR4SGmT2S/pdr6JSRfZB+IbX\r\nD7YJeq5YyYOIqHp1BdfUvCyHtfAuy++zc+pQUpkcLIFbGqVCPWhHgPsnxIol\r\naHOaT07CzplPRFnCVqujsQAQiAl++skoLp2mym/blbr1ox69eTpBS0n224Ci\r\nP5zxggex9/4g958gm7SJN+U+QfZXQ554CKk6XABNy5tv5E8UwCB7K5o+TRkA\r\neXA3g5Kl66qxdcJNcRwNMRMhi8HVdJaCLyd3KaXm1KWdC7pd3gL+rrVlaxPA\r\ntotMq6ebZ83FdRy6eCOnWgmNK69j/RM7C/4jIG8HXUwLsl1W6pWjgFwyb11S\r\n1vSg9Pj5o4LHSgLhWIXKRDKwj/63QvqgLIiG/eN2GYG4wg3DRRjYGZg/jYZ3\r\n3GUO3zoLagJlF/3Hiouz0lN1PVnB7J5E9UE=\r\n=6SE/\r\n-----END PGP SIGNATURE-----\r\n","size":29984,"noattachment":false,"key":"/fast-copy/-/fast-copy-3.0.0-beta.8.tgz"},"_npmUser":{"name":"planttheidea","email":"tony.quetano@planttheidea.com"},"directories":{},"maintainers":[{"name":"planttheidea","email":"tony.quetano@planttheidea.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fast-copy_3.0.0-beta.8_1664677762845_0.569024536398026"},"_hasShrinkwrap":false,"publish_time":1664677763046,"_cnpm_publish_time":1664677763046,"dist-tags":{"latest":"4.3.1","latest-v2":"2.2.0","latest-v3":"3.1.0"}}