{"library":"shallow-clone","title":"Shallow Clone Utility","description":"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.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install shallow-clone"],"cli":null},"imports":["import clone from 'shallow-clone';","const clone = require('shallow-clone');","import clone from 'shallow-clone';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import clone from 'shallow-clone';\n\nconst originalArray = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];\nconst clonedArray = clone(originalArray);\n\nconsole.log('Original Array:', originalArray);\nconsole.log('Cloned Array:', clonedArray);\n\n// Prove array is a new instance (shallow copy)\nconsole.log('Are arrays the same instance?', originalArray === clonedArray); // Expected: false\n\n// Prove elements are NOT cloned (references are shared)\nconsole.log('Are first elements the same instance?', originalArray[0] === clonedArray[0]); // Expected: true\n\n// Mutating a nested object in the clone affects the original\nclonedArray[0].name = 'Alicia';\nconsole.log('Original after mutation:', originalArray); // Original array's first element will also be 'Alicia'\n\nconst originalObject = { a: 1, b: { c: 2 }, d: [3, 4] };\nconst clonedObject = clone(originalObject);\n\nconsole.log('Original Object:', originalObject);\nconsole.log('Cloned Object:', clonedObject);\nconsole.log('Are objects the same instance?', originalObject === clonedObject); // Expected: false\nconsole.log('Are nested objects the same instance?', originalObject.b === clonedObject.b); // Expected: true\n","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}