shallow-clone is a JavaScript utility library designed for creating shallow copies of various data types. It supports a comprehensive range of values including primitives, plain objects, arrays, regular expressions, dates, buffers, array buffers, all JavaScript typed arrays (e.g., Int8Array, Uint8Array), Maps, and Sets. Currently at version 3.0.1, the package focuses exclusively on performing a shallow clone, which means only the top-level structure of the input value is copied. Any nested objects or arrays within the cloned structure will retain their original references. This characteristic is a key differentiator, distinguishing it from 'deep cloning' libraries like `clone-deep`, which recursively copy all nested structures. The library is considered stable and suitable for scenarios where a new top-level instance is required without altering the original, and shared references for nested data are acceptable.
npm install shallow-cloneVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use `shallow-clone` with arrays and objects, highlighting the key behavior of shallow copying where top-level structures are new instances, but nested objects retain original references.
If deep cloning is required, use a library specifically designed for it, such as `clone-deep`, or implement a recursive cloning function. Do not assume `shallow-clone` provides full immutability for complex data structures.
No fix is needed, this is the expected behavior for primitives. Developers should be aware that `clone(1)` will yield `1` and `clone('foo')` will yield `'foo'`.Evaluate if the package's stable feature set meets current project requirements. For projects requiring active development, newer language features, or potentially more robust TypeScript support out-of-the-box, consider alternatives, though for its specific shallow-clone purpose, it remains effective.
Understand the difference between shallow and deep cloning. If nested data must be independent, use a deep cloning utility (e.g., `clone-deep`) or manually recurse and clone nested structures.
For ES Modules, use `import clone from 'shallow-clone';`. Do not use `{ clone }` or `* as clone` unless specifically configured for CJS interop with TypeScript or bundlers.No dependency data recorded yet.