{"id":15387254,"url":"https://github.com/rhysd/fast-json-clone","last_synced_at":"2025-04-14T06:44:37.911Z","repository":{"id":62780722,"uuid":"562429106","full_name":"rhysd/fast-json-clone","owner":"rhysd","description":"Clone plain JSON value faster than the fastest","archived":false,"fork":false,"pushed_at":"2024-03-09T16:20:40.000Z","size":367,"stargazers_count":60,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T18:10:26.604Z","etag":null,"topics":["deep-clone","json","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fast-json-clone","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-11-06T10:36:18.000Z","updated_at":"2025-02-24T13:02:07.000Z","dependencies_parsed_at":"2024-03-09T17:42:11.627Z","dependency_job_id":null,"html_url":"https://github.com/rhysd/fast-json-clone","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"f6ce92ffb01706d2f4bc507b6a9d56bd200090cf"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Ffast-json-clone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Ffast-json-clone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Ffast-json-clone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Ffast-json-clone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/fast-json-clone/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837264,"owners_count":21169373,"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":["deep-clone","json","typescript"],"created_at":"2024-10-01T14:53:03.313Z","updated_at":"2025-04-14T06:44:37.857Z","avatar_url":"https://github.com/rhysd.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Fastest™ JSON deep clone in JavaScript\n======================================\n[![npm][npm-badge]][npm]\n[![CI][ci-badge]][ci]\n\n[fast-json-clone][npm] is a tiny library to clone [JSON][json] values in pure JavaScript focusing on the speed.\nAccording to [the benchmark](./bench), this package seems the fastest among several deep-clone implementations.\n\n```js\nimport * as assert from 'assert';\nimport cloneJSON from 'fast-json-clone';\n\nconst value = { str: 'hello', num: 42, array: [true, null], object: { str: 'hello', bool: true, } };\n\nconst cloned = cloneJSON(value);\n\nassert.deepStrictEqual(value, cloned);\nassert.notStrictEqual(value, cloned);\nassert.notStrictEqual(value.array, cloned.array);\nassert.notStrictEqual(value.object, cloned.object);\n```\n\n## Installation\n\n### Copy the source directly\n\nThis package is licensed with CC0-1.0. Directly copy [index.ts](./index.ts) to your project.\n\n### npm\n\nInstall via [npm](https://npmjs.com/) package manager.\n\n```sh\nnpm install --save fast-json-clone\n```\n\n### jsr\n\nInstall via [JSR](https://jsr.io/) package registry.\n\n```sh\n# npm\nnpx jsr add @rhy/fast-json-clone\n\n# deno\ndeno add @rhy/fast-json-clone\n```\n\n## API\n\nThis package exports a single function `cloneJSON`.\n\n```\ncloneJSON(x: JsonValue): JsonValue;\n```\n\nThis function clones the given JSON value and returns it. There are some invariants for the parameter:\n\n- The parameter must not contain circles as JSON does not allow it. This function will cause infinite loop for such values by design.\n- The parameter must contain JSON values only. Other values like `Date`, `Regexp`, `Map`, `Set`, `Buffer`, ... are not allowed.\n\n## Benchmark\n\nHere is the benchmark result with large (1.2MB) JSON value. This package is the fastest among the implementations. Please see\n[the benchmark directory](./bench) for more details and other results.\n\n\u003cimg width=889 height=439 src=\"https://github.com/rhysd/ss/blob/master/fast-json-clone/perf.png?raw=true\" alt=\"performance\"\u003e\n\n```\nNaive deep clone                x 269 ops/sec ±0.33% (90 runs sampled)\nJSON serialize/deserialize      x 144 ops/sec ±0.97% (82 runs sampled)\nNative structuredClone          x 156 ops/sec ±0.44% (79 runs sampled)\nstructuredClone polyfill        x 156 ops/sec ±0.31% (80 runs sampled)\nlodash.clonedeep                x 169 ops/sec ±2.22% (82 runs sampled)\nclone-deep                      x 239 ops/sec ±0.62% (87 runs sampled)\nrfdc (default)                  x 558 ops/sec ±0.31% (94 runs sampled)\nrfdc (proto)                    x 624 ops/sec ±0.60% (94 runs sampled)\nfastest-json-copy               x 627 ops/sec ±0.36% (94 runs sampled)\nfast-json-clone (this package)  x 664 ops/sec ±0.33% (96 runs sampled)\n\nFastest is fast-json-clone (this package)\n```\n\n## FAQ\n\n### Why is this package the fastest?\n\nSince this package is optimized for removing non-inline function calls in the hot loop as much as possible. [rfdc][] is\nimplemented with the same strategy.\n\n### Then why is this package faster than rfdc?\n\nSince this package provides less functionalities. rfdc provides support for some non-JSON types (`Date`, `Regexp`, ...).\nIt increases the number of branches in the hot loop so it causes trade-off in performance.\n\n## License\n\nThis package is distributed under [CC0 1.0](LICENSE.txt) (Public Domain).\nFeel free to copy and paste the implementation directly to your project without any copyright notice.\n\n[ci]: https://github.com/rhysd/fast-json-clone/actions/workflows/ci.yml\n[ci-badge]: https://github.com/rhysd/fast-json-clone/actions/workflows/ci.yml/badge.svg\n[npm]: https://www.npmjs.com/package/fast-json-clone\n[npm-badge]: https://badge.fury.io/js/fast-json-clone.svg\n[json]: https://json.org/\n[rfdc]: https://github.com/davidmarkclements/rfdc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Ffast-json-clone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Ffast-json-clone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Ffast-json-clone/lists"}