deep-copy-ts is a utility library for JavaScript and TypeScript designed to create robust deep copies (clones) of various data structures. It accurately duplicates a broad spectrum of primitive values, objects, arrays, and complex built-in types such as Date, RegExp, ArrayBuffer, DataView, and various TypedArrays (Float32Array, Int8Array, etc.). The current stable version is 0.5.4, indicating it is pre-1.0.0 and may undergo breaking changes in future minor releases. While a specific release cadence is not published, the active versioning suggests ongoing development. A key differentiator is its comprehensive handling of numerous JavaScript built-in types and its TypeScript-first approach, offering type safety and reliable deep cloning without mutating the original object.
npm install deep-copy-tsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `deepCopy` to duplicate an object containing various primitive and complex data types, including nested structures, dates, regexps, functions, and typed arrays. It then verifies that modifications to the copied object's nested properties do not affect the original object, illustrating the deep cloning behavior. It also shows that functions are copied by reference.
Ensure browser compatibility requirements are met, potentially by avoiding these specific TypedArray types or implementing environment-specific fallbacks.
Be aware of this behavior and manually handle custom logic for duplicating functions or Promises if deep cloning their internal state is required.
Test the library's behavior with objects containing circular references in your specific environment. If an error occurs, consider pre-processing your objects to break circular references or using a different library that explicitly guarantees circular reference handling.
Pin to exact versions for production environments or conduct thorough regression testing when updating to new minor versions.
Ensure you are using `import { deepCopy } from 'deep-copy-ts';` for ES Modules. If in a CommonJS-only environment, use `const { deepCopy } = require('deep-copy-ts');`. Verify your bundler configuration correctly handles ES Modules.Inspect the object you are attempting to copy for circular references. If they exist, either restructure your data to avoid them or use a deep cloning utility that explicitly supports and handles circular references, often by tracking visited objects.
No dependency data recorded yet.