{"id":19621344,"url":"https://github.com/commenthol/clones","last_synced_at":"2025-04-28T03:32:18.171Z","repository":{"id":57200596,"uuid":"82386229","full_name":"commenthol/clones","owner":"commenthol","description":"should deep clone everything even global objects, functions, circularities, ...","archived":false,"fork":false,"pushed_at":"2019-01-01T20:48:41.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T08:45:03.032Z","etag":null,"topics":["array","circular","clone","deep","javascript","object"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/commenthol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-18T12:46:27.000Z","updated_at":"2019-07-04T08:10:17.000Z","dependencies_parsed_at":"2022-09-06T10:51:06.076Z","dependency_job_id":null,"html_url":"https://github.com/commenthol/clones","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fclones","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fclones/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fclones/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fclones/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commenthol","download_url":"https://codeload.github.com/commenthol/clones/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251246256,"owners_count":21558761,"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":["array","circular","clone","deep","javascript","object"],"created_at":"2024-11-11T11:22:26.116Z","updated_at":"2025-04-28T03:32:17.445Z","avatar_url":"https://github.com/commenthol.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clones\n\n[![NPM version](https://badge.fury.io/js/clones.svg)](https://www.npmjs.com/package/clones/)\n\n\u003e should deep clone everything even global objects, functions, circularities, ...\n\nCompanion for [safer-eval](https://github.com/commenthol/safer-eval).\n\nRuns on node and in modern browsers:\n\n|                | Versions |\n| ---            | ---      |\n| **node**       | ~~0.12~~, 4, 6, 8, 10, 11  |\n| **Chrome**     | 55, 56, 71 |\n| **Firefox**    | 45, 51, 64 |\n| **Edge**       | 14, 16   |\n| **IE**         | ~~11~~   |\n| **Safari**     | 10       |\n| **iOS Safari** | 10       |\n\n## Installation\n\n```\nnpm i -S clones\n```\n\n## Usage\n\n```js\nconst clones = require('clones')\nconst dest = clones(source, [bind])\n```\n\n**Parameters**\n\n**Parameters**\n\n**source**: `Object`, clone source\n\n**bind**: `Object`, bind functions to this context\n\n**Returns**: `Any`, deep clone of `source`\n\n**Example**:\n```js\nconst clones = require('clones')\n\nvar source = {\n  obj: {a: {b: 1}},\n  arr: [true, 1, {c: 'dee'}],\n  fn: function () { return this.number + 12 }\n}\n// adding circularity\nsource.obj.a.e = source.obj.a\n\n// do the cloning (with binding a context)\nvar dest = clones(source, {number: 30})\n// =\u003e { obj: { a: { b: 1, e: [Circular] }, d: 2017-02-17T21:57:44.576Z },\n//      arr: [ true, 1, { c: 'dee' } ],\n//      fn: [Function: fn] }\n\n// checks\nassert.ok(dest !== source)                      // has different reference\nassert.ok(dest.obj !== source.obj)              // has different reference\nassert.ok(dest.obj.a !== source.obj.a)          // has different reference\nassert.ok(dest.obj.a.e !== source.obj.a.e)      // different references for circularities\nassert.equal(dest.obj.d.toISOString(),\n  source.obj.d.toISOString())                   // has same content\nassert.ok(dest.fn !== source.fn)                // has different function reference\nsource.fn = source.fn.bind({number: 29})        // bind `this` for `source`\nassert.equal(dest.fn(), source.fn() + 1)        // returning the same result\n```\n\n### Clone prototypes or classes\n\n```js\nconst clones = require('clones')\n// clone built in `Array`\nconst C = clones.classes(Array)\n\nlet c = new C(1,2,3)\n// =\u003e [1, 2, 3]\nc.reverse()\n// =\u003e [3, 2, 1]\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fclones","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommenthol%2Fclones","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fclones/lists"}