{"id":21305026,"url":"https://github.com/maximilianmairinger/circclone","last_synced_at":"2025-10-06T08:07:25.207Z","repository":{"id":106633321,"uuid":"609522341","full_name":"maximilianMairinger/circClone","owner":"maximilianMairinger","description":"Simple lib to savely clone circular objects.","archived":false,"fork":false,"pushed_at":"2024-01-28T17:01:17.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"V2","last_synced_at":"2025-08-09T03:18:45.335Z","etag":null,"topics":["circ","circular","clone","copy","cyclic","object","recursive","self-referencing","simple"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/circ-clone","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maximilianMairinger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-03-04T12:40:57.000Z","updated_at":"2023-10-12T17:46:24.000Z","dependencies_parsed_at":"2024-01-28T15:47:39.911Z","dependency_job_id":"8f17eb9c-1981-4214-94c6-c5900e29f199","html_url":"https://github.com/maximilianMairinger/circClone","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"94e03a9c75df1498a3c63e7dd09ae4e35c6c53c1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maximilianMairinger/circClone","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FcircClone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FcircClone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FcircClone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FcircClone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximilianMairinger","download_url":"https://codeload.github.com/maximilianMairinger/circClone/tar.gz/refs/heads/V2","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FcircClone/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278577929,"owners_count":26009703,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["circ","circular","clone","copy","cyclic","object","recursive","self-referencing","simple"],"created_at":"2024-11-21T16:16:40.095Z","updated_at":"2025-10-06T08:07:25.081Z","avatar_url":"https://github.com/maximilianMairinger.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Circ clone\r\n\r\nSimple lib to safely (regarding [prototype poisoning](https://medium.com/intrinsic-blog/javascript-prototype-poisoning-vulnerabilities-in-the-wild-7bc15347c96)) clone circular (deep) objects. Exports three functions: `cloneKeys`, `mergeDeep` and `cloneKeysButKeepSym`, that do what they say and are not configurable. They are properly types and support tree-shaking. Each implementation is considerable simple (thus small). All functions that keep track of circular references, use `WeakMap` to do so.\r\n\r\n## Installation\r\n\r\n```shell\r\n $ npm i circ-clone\r\n```\r\n\r\n## Usage\r\n\r\n### Clone keys\r\n\r\n`cloneKeys\u003cOb extends Object\u003e(ob: Ob): Ob`\r\n\r\n```ts\r\nimport { cloneKeys } from \"circ-clone\"\r\n\r\nconst obj = { a: 1, b: { c: 3 } }\r\nobj.b.d = obj\r\n\r\nconst cloned = cloneKeys(obj)\r\n```\r\n\r\n### Merge deep\r\n\r\n`mergeDeep\u003cInto extends object, From extends object\u003e(from: From, into: Into): Into \u0026 From`\r\n\r\nMerges the properties of `from` into `into` recursively with support for cyclic references. References from `from` to `into` (or any of its nested objects) are not supported, as the resulting behavior is not defined. Arrays are not treated specially (indexes are overwritten). The return value is `=== into` (thus not cloned), only sub-branches (nested objects) of from that are new to into are cloned.\r\n\r\n```ts\r\nimport { mergeDeep } from \"circ-clone\"\r\n\r\nconst into = { a: 2, b: { c: 4, d: { doesntMatter: \"whats in here\", asItGets: \"overriden\" } } }\r\nconst from = { a: 1, b: { c: 3, d: \"see one line below\" } }\r\nfrom.b.d = from\r\n\r\n\r\nconst merged = mergeDeep(into, from)\r\n// merged = into = {\r\n//   a: 1,\r\n//   b: {\r\n//     c: 3,\r\n//     d: [Circular]\r\n//   }\r\n// }\r\n```\r\n\r\n\u003e Importantly note, that the fields on `into.b.d` do not get copied over, as the reference to `from.b.d` is considered new. The reason for this decision is that it seems unintuitive for members of into to suddenly be written into a place of into. If you however need this behavior, please let me know by creating an issue.\r\n\r\n### Merge deep but not cyclic\r\n\r\n`mergeDeepButNotCyclic\u003cInto extends object, From extends object\u003e(from: From, into: Into): Into \u0026 From`\r\n\r\nMerges the properties of `from` into `into` without considering cyclic references! This is faster than `mergeDeep`, but has the drawback that cyclic references in both `from` and `into` (exclusively if in both at the same place) terminate the function with an (stackoverflow) exception, similar to how `JSON.stringify` would. Also note that references from `from` to `into` (or any of its nested objects) are not supported, as the resulting behavior is not defined. The return value is `=== into` (thus not cloned), only sub-branches (nested objects) of from that are new to into are cloned.\r\n\r\n```ts\r\nimport { mergeDeepButNotCyclic } from \"circ-clone\"\r\n\r\nconst into = { a: 2, b: { c: 4, e: 5 } }\r\nconst from = { a: 1, b: { c: 3 } }\r\n\r\nconst merged = mergeDeepButNotCyclic(into, from)\r\n// merged = into = {\r\n//   a: 1,\r\n//   b: {\r\n//     c: 3,\r\n//     e: 5\r\n//   }\r\n// }\r\n```\r\n\r\n### Clone keys but keep symbols\r\n\r\n`cloneKeysButKeepSym\u003cOb extends Object\u003e(ob: Ob): Ob`\r\n\r\nSimilar to `cloneKeys` but keeps symbols uncloned!\r\n\r\n```ts\r\nimport { cloneKeysButKeepSym } from \"circ-clone\"\r\n\r\nconst obj = { a: 1, b: { c: 3 } }\r\nobj.b.d = obj\r\nconst sym = Symbol(\"foo\")\r\nobj[sym] = {  }\r\n\r\n\r\nconst cloned = cloneKeysButKeepSym(obj)\r\ncloned[sym] === obj[sym] // true\r\n```\r\n\r\n## Contribute\r\n\r\nAll feedback is appreciated. Create a pull request or write an issue.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianmairinger%2Fcircclone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximilianmairinger%2Fcircclone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianmairinger%2Fcircclone/lists"}