{"id":26704955,"url":"https://github.com/stacksjs/ts-clone","last_synced_at":"2025-03-27T05:19:41.153Z","repository":{"id":284469668,"uuid":"955037353","full_name":"stacksjs/ts-clone","owner":"stacksjs","description":"Deeply clone arbitrary objects using TypeScript.","archived":false,"fork":false,"pushed_at":"2025-03-26T04:14:16.000Z","size":0,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T04:15:14.835Z","etag":null,"topics":["clone","library","objects","typescript"],"latest_commit_sha":null,"homepage":"","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/stacksjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["stacksjs","chrisbbreuer"],"open_collective":"stacksjs"}},"created_at":"2025-03-26T02:26:32.000Z","updated_at":"2025-03-26T04:14:18.000Z","dependencies_parsed_at":"2025-03-26T04:15:19.727Z","dependency_job_id":"57b88e4f-80b4-4dd3-b617-675dee39dac9","html_url":"https://github.com/stacksjs/ts-clone","commit_stats":null,"previous_names":["stacksjs/ts-clone"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-clone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-clone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-clone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-clone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacksjs","download_url":"https://codeload.github.com/stacksjs/ts-clone/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245785973,"owners_count":20671659,"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","library","objects","typescript"],"created_at":"2025-03-27T05:19:40.496Z","updated_at":"2025-03-27T05:19:41.136Z","avatar_url":"https://github.com/stacksjs.png","language":"TypeScript","funding_links":["https://github.com/sponsors/stacksjs","https://github.com/sponsors/chrisbbreuer","https://opencollective.com/stacksjs"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\".github/art/cover.jpg\" alt=\"Social Card of this repo\"\u003e\u003c/p\u003e\n\n[![npm version](https://img.shields.io/npm/v/ts-clone.svg)](https://www.npmjs.com/package/ts-clone)\n[![GitHub Actions][github-actions-src]][github-actions-href]\n[![Bundle Size](https://img.shields.io/bundlephobia/minzip/ts-clone)](https://bundlephobia.com/package/ts-clone)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.8%2B-blue)](https://www.typescriptlang.org/)\n\n# ts-clone\n\nA high-performance, type-safe deep cloning utility for TypeScript and JavaScript applications.\n\n## Features\n\n- 🚀 **High Performance** _Optimized for speed and minimal memory footprint_\n- 🔄 **Circular References** _Handles circular references in objects by default_\n- 📊 **Comprehensive Support** _Clones objects, arrays, dates, RegExp, Maps, Sets, and more_\n- 🛡️ **Type Safety** _Full TypeScript support with accurate type preservation_\n- 🔧 **Configurable** _Control clone depth and prototype handling_\n- 💎 **ES6+ Support** _Works with modern JavaScript features like Map, Set, Symbol, and Promise_\n\n## Installation\n\n```bash\n# Using npm\nnpm install ts-clone\n\n# Using yarn\nyarn add ts-clone\n\n# Using pnpm\npnpm add ts-clone\n\n# Using bun\nbun add ts-clone\n```\n\n## Quick Start\n\n```typescript\nimport { clone } from 'ts-clone'\n\n// Simple cloning\nconst original = { name: 'John', roles: ['admin', 'user'] }\nconst cloned = clone(original)\n\n// Handles circular references\nconst circular = { prop: 'value' }\ncircular.self = circular\nconst clonedCircular = clone(circular) // Works without infinite loops\n\n// Clone with specified depth\nconst nested = { level1: { level2: { level3: 'deep' } } }\nconst shallow = clone(nested, true, 1) // Only clones the first level\n\n// Clone with options object\nconst obj = { hidden: 'property' }\nObject.defineProperty(obj, 'hidden', { enumerable: false })\nconst withNonEnumerable = clone(obj, {\n  includeNonEnumerable: true\n})\n```\n\n## Advanced Usage\n\n```typescript\n// Clone RegExp objects with their flags and lastIndex\nconst regex = /pattern/gi\nregex.lastIndex = 5\nconst clonedRegex = clone(regex)\nconsole.log(clonedRegex.source) // 'pattern'\nconsole.log(clonedRegex.flags) // 'gi'\nconsole.log(clonedRegex.lastIndex) // 5\n\n// Clone ES6+ objects\nconst map = new Map([['key', 'value']])\nconst set = new Set(['item1', 'item2'])\nconst promise = Promise.resolve('data')\n\nconst clonedMap = clone(map)\nconst clonedSet = clone(set)\nconst clonedPromise = clone(promise)\n\n// Clone with prototype handling\nconst proto = { shared: 'value' }\nconst instance = Object.create(proto)\ninstance.own = 'property'\n\n// Clone with original prototype\nconst clonedWithProto = clone(instance)\nconsole.log(clonedWithProto.shared) // 'value'\n\n// Clone with custom prototype\nconst clonedCustomProto = clone(instance, true, Infinity, {})\nconsole.log(clonedCustomProto.shared) // undefined\n```\n\n## Utility Functions\n\n```typescript\n// Clone just the prototype\nconst proto = {\n  method() {\n    return 'result'\n  }\n}\n\nconst protoClone = clone.clonePrototype(proto)\n\n// Type checking utilities\nclone.__isArray([1, 2, 3]) // true\nclone.__isDate(new Date()) // true\nclone.__isRegExp(/pattern/) // true\n\n// RegExp flags extraction\nclone.__getRegExpFlags(/pattern/gi) // 'gim'\n```\n\n## Use Cases\n\n- **Deep Copying Objects**: Create true copies without reference sharing\n- **API Response Processing**: Safely modify cloned API responses without side effects\n- **State Management**: Immutable state updates in frameworks like React/Redux\n- **Object Serialization**: Pre-process objects before serialization\n- **Defensive Programming**: Protect internal data structures from external modifications\n\n## Contributing\n\nPlease see the [Contributing Guide](https://github.com/stacksjs/contributing) for details.\n\n## Community\n\nFor help, discussion about best practices, or any other conversation that would benefit from being searchable:\n\n[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)\n\nFor casual chit-chat with others using this package:\n\n[Join the Stacks Discord Server](https://discord.gg/stacksjs)\n\n## Postcardware\n\n“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.\n\nOur address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎\n\n## Sponsors\n\nWe would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.\n\n- [JetBrains](https://www.jetbrains.com/)\n- [The Solana Foundation](https://solana.com/)\n\n## Credits\n\n- [Original `clone` module](https://github.com/pvorb/clone) _for the initial implementation inspiration_\n- [Chris Breuer](https://github.com/chrisbbreuer)\n- [All Contributors](https://github.com/stacksjs/ts-clone/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.\n\nMade with 💙\n\n[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/ts-clone/ci.yml?style=flat-square\u0026branch=main\n[github-actions-href]: https://github.com/stacksjs/ts-clone/actions?query=workflow%3Aci\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fts-clone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacksjs%2Fts-clone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fts-clone/lists"}