{"id":19408574,"url":"https://github.com/morglod/sdfclone","last_synced_at":"2025-04-24T09:31:55.845Z","repository":{"id":217690120,"uuid":"744618158","full_name":"Morglod/sdfclone","owner":"Morglod","description":"World fastest deep clone based on schema","archived":false,"fork":false,"pushed_at":"2024-01-17T20:01:19.000Z","size":55,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T03:11:12.471Z","etag":null,"topics":["clone","deep","deepclone","performance"],"latest_commit_sha":null,"homepage":"","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/Morglod.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}},"created_at":"2024-01-17T17:04:52.000Z","updated_at":"2024-04-19T21:27:00.000Z","dependencies_parsed_at":"2024-01-17T23:24:46.320Z","dependency_job_id":"4738cb48-3a56-40c8-8521-263928a4ca75","html_url":"https://github.com/Morglod/sdfclone","commit_stats":null,"previous_names":["morglod/sdfclone"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsdfclone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsdfclone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsdfclone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morglod%2Fsdfclone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morglod","download_url":"https://codeload.github.com/Morglod/sdfclone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250600722,"owners_count":21457018,"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","deep","deepclone","performance"],"created_at":"2024-11-10T12:06:35.646Z","updated_at":"2025-04-24T09:31:55.507Z","avatar_url":"https://github.com/Morglod.png","language":"TypeScript","readme":"[![NPM Version](https://badge.fury.io/js/sdfclone.svg?style=flat)](https://www.npmjs.com/package/sdfclone)\n[![Size](https://img.shields.io/bundlephobia/minzip/sdfclone)](https://gitHub.com/Morglod/sdfclone/)\n\n# sdfclone\n\nWorld fastest schema based deep clone for js (as for Jan 2024)\n\nSuited for immutable objects with defined structure.\n\n-   ⚡️ +-1% slower than optimal manually written code ⚡️\n-   12x faster than structuredClone\n-   no deps\n-   detect cycles (optional)\n-   support all JSON types\n-   support most of JS types\n-   support custom functions\n-   variants not supported yet 😬\n-   tested with `rfdc` tests\n\n## Usage\n\n```js\nimport { createCloner } from \"sdfclone\";\n\n// define schema\nconst objectSchema = {\n    x: Number,\n    y: {\n        z: String,\n        c: {\n            bb: Date,\n            bb2: Function,\n        },\n        gg: [{ ff: Number, hh: Number }],\n    },\n};\n\n// create cloner\nconst cloner = createCloner(objectSchema);\n\n// or with cycle detector; detectCycles=false by default\nconst cloner = createCloner(objectSchema, { detectCycles: true });\n\n// clone!\nconst newObject = cloner(object);\n```\n\nor less verbose variant:\n\n```js\nimport { createCloner, createCloneSchemaFrom } from \"sdfclone\";\n\nlet alreadyCreatedObject = { ... };\n\n// extract schema from object\nconst objectSchema = createCloneSchemaFrom(alreadyCreatedObject);\n\n// create cloner\nconst cloner = createCloner(objectSchema);\n\n// than clone!\nconst newObject = cloner(alreadyCreatedObject);\n```\n\n## Benchmark\n\nbun 1.0.21 macbook m1\n\n```\nnaive x 3,789,560 ops/sec ±0.64% (95 runs sampled)\noptimal x 7,908,207 ops/sec ±0.75% (94 runs sampled) \u003c----------------------\nJSON.parse x 1,257,746 ops/sec ±0.33% (98 runs sampled)\nsdfclone x 7,825,037 ops/sec ±0.70% (94 runs sampled)   \u003c----------------------\nsdfclone detect cycles x 6,582,222 ops/sec ±0.62% (96 runs sampled)\nsdfclone with create x 759,116 ops/sec ±0.44% (95 runs sampled)\nsdfclone with schema get and create x 535,369 ops/sec ±0.35% (97 runs sampled)\nstructured clone x 666,819 ops/sec ±0.63% (93 runs sampled)\nrfdc x 3,091,196 ops/sec ±0.36% (96 runs sampled)\nlodash cloneDeep x 695,643 ops/sec ±0.32% (97 runs sampled)\nfastestJsonCopy x 4,042,250 ops/sec ±0.44% (97 runs sampled)\n```\n\nnode 18.18.0\n\n```\nnaive x 2,562,532 ops/sec ±0.96% (96 runs sampled)\noptimal x 6,024,499 ops/sec ±0.89% (93 runs sampled) \u003c----------------------\nJSON.parse x 467,411 ops/sec ±0.44% (98 runs sampled)\nsdfclone x 6,173,111 ops/sec ±0.55% (97 runs sampled) \u003c----------------------\nsdfclone detect cycles x 4,261,157 ops/sec ±0.85% (95 runs sampled)\nsdfclone with create x 663,451 ops/sec ±0.51% (96 runs sampled)\nsdfclone with schema get and create x 434,197 ops/sec ±0.89% (100 runs sampled)\nstructured clone x 470,649 ops/sec ±0.45% (99 runs sampled)\nrfdc x 2,220,032 ops/sec ±0.26% (97 runs sampled)\nlodash cloneDeep x 516,606 ops/sec ±0.31% (99 runs sampled)\nfastestJsonCopy x 2,266,253 ops/sec ±0.54% (98 runs sampled)\n```\n\n## Schema description\n\n```js\n// array\n[ itemSchema ]\n\n// object\n{ field: fieldSchema }\n\n// JSON values\nnull | Number | String | Boolean\n\n// JS values\nundefined | Number | String | Boolean | Function | Symbol | BigInt | Date\n\n// buffers \u0026 typed arrays\nBuffer | ArrayBuffer | any TypedArrays\n\n// specific JS\nMap | Set // this uses JSON.parse(JSON.stringify) technique by default\n// use `new ClonerMap(valueSchema)` or `new ClonerSet(valueSchema)` when possible\n\n// for arguments or iterators\n// use `new ClonerArrayLike(itemSchema)`\n\n```\n\nIts also possible to pass custom cloner function with:  \n`new ClonerCustomFn(customCloner: x =\u003e x)`\n\n## Utils\n\nCreate schema from existing object:\n\n```js\nconst obj = { ... };\n\n// create schema\nconst objSchema = createCloneSchemaFrom(obj);\n\n// with option that will also walk inside prototypes cloneProto=false by default\nconst objSchemaWithProto = createCloneSchemaFrom(obj, { cloneProto: true });\n\nconst cloner = createCloner(objSchema);\n\nconst newObject = cloner(obj);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorglod%2Fsdfclone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorglod%2Fsdfclone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorglod%2Fsdfclone/lists"}