{"id":17448307,"url":"https://github.com/mesqueeb/copy-anything","last_synced_at":"2025-05-16T07:06:44.293Z","repository":{"id":33781374,"uuid":"161923065","full_name":"mesqueeb/copy-anything","owner":"mesqueeb","description":"An optimised way to copy'ing (cloning) an Object or Array. A small and simple integration","archived":false,"fork":false,"pushed_at":"2025-03-24T18:18:25.000Z","size":1463,"stargazers_count":48,"open_issues_count":7,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-14T01:24:18.139Z","etag":null,"topics":["clone","clone-objects","copy","copy-objects","deep-clone","deep-copy","json-stringify","json-stringify-json-parse","object","stringify-parse"],"latest_commit_sha":null,"homepage":"https://npmjs.com/copy-anything","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mesqueeb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"mesqueeb","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2018-12-15T16:26:26.000Z","updated_at":"2025-05-09T09:54:00.000Z","dependencies_parsed_at":"2024-06-05T02:35:33.799Z","dependency_job_id":"7e5888d5-1bc9-487e-9512-0fa2c0ea0618","html_url":"https://github.com/mesqueeb/copy-anything","commit_stats":{"total_commits":66,"total_committers":4,"mean_commits":16.5,"dds":0.5303030303030303,"last_synced_commit":"57c4f183a8037f99a54af5a950b53cca3d65ea4d"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcopy-anything","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcopy-anything/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcopy-anything/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcopy-anything/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mesqueeb","download_url":"https://codeload.github.com/mesqueeb/copy-anything/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485066,"owners_count":22078767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clone","clone-objects","copy","copy-objects","deep-clone","deep-copy","json-stringify","json-stringify-json-parse","object","stringify-parse"],"created_at":"2024-10-17T20:06:57.570Z","updated_at":"2025-05-16T07:06:39.283Z","avatar_url":"https://github.com/mesqueeb.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mesqueeb"],"categories":[],"sub_categories":[],"readme":"# Copy anything 🎭\n\n\u003ca href=\"https://www.npmjs.com/package/copy-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/copy-anything.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/copy-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/copy-anything.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\n```\nnpm i copy-anything\n```\n\nAn optimised way to copy'ing (cloning) an object or array. A small and simple integration.\n\n## Motivation\n\nI created this package because I tried a lot of similar packages that do copy'ing/cloning. But all had its quirks, and _all of them break things they are not supposed to break_... 😞\n\nI was looking for:\n\n- a simple copy/clone function\n- has to be fast!\n- props must lose any reference to original object\n- works with arrays and objects in arrays!\n- supports symbols\n- can copy non-enumerable props as well\n- **does not break special class instances**　‼️\n\nThis last one is crucial! So many libraries use custom classes that create objects with special prototypes, and such objects all break when trying to copy them improperly. So we gotta be careful!\n\ncopy-anything will copy objects and nested properties, but only as long as they're \"plain objects\". As soon as a sub-prop is not a \"plain object\" and has a special prototype, it will copy that instance over \"as is\". ♻️\n\n## Meet the family (more tiny utils with TS support)\n\n- [is-what 🙉](https://github.com/mesqueeb/is-what)\n- [is-where 🙈](https://github.com/mesqueeb/is-where)\n- [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)\n- [check-anything 👁](https://github.com/mesqueeb/check-anything)\n- [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)\n- [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)\n- [map-anything 🗺](https://github.com/mesqueeb/map-anything)\n- [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)\n- [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)\n- [case-anything 🐫](https://github.com/mesqueeb/case-anything)\n- [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)\n- [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)\n\n## Usage\n\n\u003c!-- prettier-ignore-start --\u003e\n```js\nimport { copy } from 'copy-anything'\n\nconst original = { name: 'Ditto', type: { water: true } }\nconst copy = copy(original)\n\n// now if we change a nested prop like the type\ncopy.type.water = false\n// or add a new nested prop\ncopy.type.fire = true\n\n// then the original object will still be the same:\n(original.type.water === true) // true\n(original.type.fire === undefined) // true\n```\n\n\u003e Please note, by default copy-anything does not copy non-enumerable props. If you need to copy those, see the instructions further down below.\n\n## Works with arrays\n\nIt will also clone arrays, **as well as objects inside arrays!** 😉\n\n```js\nconst original = [{ name: 'Squirtle' }]\nconst copy = copy(original)\n\n// now if we change a prop in the array\ncopy[0].name = 'Wartortle'\n// or add a new item to the array\ncopy.push({ name: 'Charmander' })\n\n// then the original array will still be the same:\n(original[0].name === 'Squirtle') // true\n(original[1] === undefined) // true\n```\n\n## Non-enumerable\n\nBy default, copy-anything only copies enumerable properties. If you also want to copy non-enumerable properties you can do so by passing that as an option.\n\n```js\nconst original = { name: 'Bulbasaur' }\n// bulbasaur's ID is non-enumerable\nObject.defineProperty(original, 'id', {\n  value: '001',\n  writable: true,\n  enumerable: false,\n  configurable: true,\n})\nconst copy1 = copy(original)\n(copy1.id === undefined) // true\n\nconst copy2 = copy(original, { nonenumerable: true })\n(copy2.id === '001') // true\n```\n\n## Limit to specific props\n\nYou can limit to specific props.\n\n```js\nconst original = { name: 'Flareon', type: ['fire'], id: '136' }\nconst copy = copy(original, { props: ['name'] })\n\n(copy) // will look like: `{ name: 'Flareon' }`\n```\n\n\u003e Please note, if the props you have specified are non-enumerable, you will also need to pass `{nonenumerable: true}`.\n\n\u003c!-- prettier-ignore-end --\u003e\n\n## Source code\n\nThe source code is literally just these lines. Most of the magic comes from the isPlainObject function from the [is-what library](https://github.com/mesqueeb/is-what).\n\n```JavaScript\nimport { isPlainObject } from 'is-what'\n\nexport function copy (target) {\n  if (isArray(target)) return target.map(i =\u003e copy(i))\n  if (!isPlainObject(target)) return target\n  return Object.keys(target)\n    .reduce((carry, key) =\u003e {\n      const val = target[key]\n      carry[key] = copy(val)\n      return carry\n    }, {})\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fcopy-anything","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmesqueeb%2Fcopy-anything","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fcopy-anything/lists"}