{"name":"@stdlib/utils-copy","version":"0.2.3","description":"Copy or deep clone a value to an arbitrary depth.","license":"Apache-2.0","author":{"name":"The Stdlib Authors","url":"https://github.com/stdlib-js/stdlib/graphs/contributors"},"contributors":[{"name":"The Stdlib Authors","url":"https://github.com/stdlib-js/stdlib/graphs/contributors"}],"main":"./lib","browser":{"process":"process/"},"directories":{"doc":"./docs","lib":"./lib","dist":"./dist"},"types":"./docs/types","scripts":{},"homepage":"https://stdlib.io","repository":{"type":"git","url":"git://github.com/stdlib-js/utils-copy.git"},"bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"dependencies":{"@stdlib/array-float32":"^0.2.2","@stdlib/array-float64":"^0.2.3","@stdlib/array-int16":"^0.2.3","@stdlib/array-int32":"^0.2.3","@stdlib/array-int8":"^0.2.3","@stdlib/array-uint16":"^0.2.3","@stdlib/array-uint32":"^0.2.3","@stdlib/array-uint8":"^0.2.3","@stdlib/array-uint8c":"^0.2.3","@stdlib/assert-has-own-property":"^0.2.3","@stdlib/assert-is-array":"^0.2.3","@stdlib/assert-is-buffer":"^0.2.3","@stdlib/assert-is-error":"^0.2.3","@stdlib/assert-is-nonnegative-integer":"^0.2.3","@stdlib/buffer-from-buffer":"^0.2.3","@stdlib/constants-float64-pinf":"^0.2.3","@stdlib/string-format":"^0.2.3","@stdlib/utils-define-property":"^0.2.5","@stdlib/utils-get-prototype-of":"^0.2.3","@stdlib/utils-index-of":"^0.2.3","@stdlib/utils-keys":"^0.2.3","@stdlib/utils-property-descriptor":"^0.2.3","@stdlib/utils-property-names":"^0.2.3","@stdlib/utils-regexp-from-string":"^0.2.3","@stdlib/utils-type-of":"^0.2.3","@stdlib/error-tools-fmtprodmsg":"^0.2.3"},"devDependencies":{},"engines":{"node":">=0.10.0","npm":">2.7.0"},"os":["aix","darwin","freebsd","linux","macos","openbsd","sunos","win32","windows"],"keywords":["stdlib","stdutils","stdutil","utilities","utils","util","copy","cp","clone","deep","deepcopy","deepclone","shallow","shallowcopy","array","object","date","regexp","typed array","set","map","error","err","uri","urierror","syntax","syntaxerror","reference","referenceerror","type","typeerror","eval","evalerror","range","rangeerror"],"funding":{"type":"opencollective","url":"https://opencollective.com/stdlib"},"_id":"@stdlib/utils-copy@0.2.3","gitHead":"65ac870bcc9363ee25cdde72514d9e0783b5395e","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Fc91OpBuHZAZpWO/8ZZQTGaCvaMX3KZe2cVD5eMZjYQ88/PGVl/y/zY5KsKbc7A46/IbDw2GD757ii0Bv+zNlg==","shasum":"20f13603610e77ab5948d6f25cb12943a61a2fe7","tarball":"http://registry-npm.ywwl.com/@stdlib/utils-copy/download/@stdlib/utils-copy-0.2.3.tgz","fileCount":13,"unpackedSize":66000,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD5RH2+EWQFc1wo3a993QMsBAiD1Syzx6bIknkWQkUJuQIgfUy6q81lFNe9bV9AUF9Xwmgsi/fx8bfQ15hQ1H6YuRY="}],"size":16549,"noattachment":false,"key":"/@stdlib/utils-copy/-/@stdlib/utils-copy-0.2.3.tgz"},"_npmUser":{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},"maintainers":[{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/utils-copy_0.2.3_1770525483857_0.5376862178855497"},"_hasShrinkwrap":false,"readme":"<!--\n\n@license Apache-2.0\n\nCopyright (c) 2018 The Stdlib Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n-->\n\n\n<details>\n  <summary>\n    About stdlib...\n  </summary>\n  <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>\n  <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>\n  <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>\n  <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href=\"https://github.com/stdlib-js/stdlib\">GitHub</a>, and please consider <a href=\"https://opencollective.com/stdlib\">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>\n</details>\n\n# Copy\n\n[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->\n\n> Copy or deep clone a value to an arbitrary depth.\n\n<section class=\"installation\">\n\n## Installation\n\n```bash\nnpm install @stdlib/utils-copy\n```\n\n</section>\n\n<section class=\"usage\">\n\n## Usage\n\n```javascript\nvar copy = require( '@stdlib/utils-copy' );\n```\n\n#### copy( value\\[, level] )\n\nCopies or deep clones an input `value` to an arbitrary depth. The function accepts both `objects` and `primitives`.\n\n```javascript\n// Primitives...\nvar out = copy( 'beep' );\n// returns 'beep'\n\n// Objects...\nvar value = [\n    {\n        'a': 1,\n        'b': true,\n        'c': [ 1, 2, 3 ]\n    }\n];\nout = copy( value );\n// returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n\nvar bool = ( value[0].c === out[0].c );\n// returns false\n\n// Error object...\nvar err1 = new TypeError( 'beep' );\n\nvar err2 = copy( err1 );\n// returns <TypeError>\n```\n\nThe default behavior returns a **full** deep copy of any `object`. To limit the copy depth, set the `level` option.\n\n```javascript\nvar value = [\n    {\n        'a': 1,\n        'b': true,\n        'c': [ 1, 2, 3 ]\n    }\n];\n\n// Trivial case => return the same reference\nvar out = copy( value, 0 );\n// returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n\nvar bool = ( value[0] === out[0] );\n// returns true\n\n// Shallow copy:\nout = copy( value, 1 );\n\nbool = ( value === out );\n// returns false\n\nbool = ( value[0] === out[0] );\n// returns true\n\n// Deep copy:\nout = copy( value, 2 );\n\nbool = ( value[0] === out[0] );\n// returns false\n\nbool = ( value[0].c === out[0].c );\n// returns true\n```\n\n</section>\n\n<!-- /.usage -->\n\n<section class=\"notes\">\n\n## Notes\n\n-   List of **supported** values/types:\n\n    -   `undefined`\n    -   `null`\n    -   `boolean`/`Boolean`\n    -   `string`/`String`\n    -   `number`/`Number`\n    -   `function`\n    -   `Object`\n    -   `Date`\n    -   `RegExp`\n    -   `Set`\n    -   `Map`\n    -   [`Error`][mdn-error]\n    -   [`URIError`][mdn-uri-error]\n    -   [`ReferenceError`][mdn-reference-error]\n    -   [`SyntaxError`][mdn-syntax-error]\n    -   [`RangeError`][mdn-range-error]\n    -   [`EvalError`][mdn-eval-error]\n    -   [`TypeError`][mdn-type-error]\n    -   [`System Error`][node-system-error] (Node.js)\n    -   `Array`\n    -   `Int8Array`\n    -   `Uint8Array`\n    -   `Uint8ClampedArray`\n    -   `Init16Array`\n    -   `Uint16Array`\n    -   `Int32Array`\n    -   `Uint32Array`\n    -   `Float32Array`\n    -   `Float64Array`\n    -   `Buffer` ([Node.js][node-buffer])\n\n-   List of **unsupported** values/types:\n\n    -   `DOMElement`: to copy DOM elements, use `element.cloneNode()`.\n    -   `Symbol`\n    -   `WeakMap`\n    -   `WeakSet`\n    -   `Blob`\n    -   `File`\n    -   `FileList`\n    -   `ImageData`\n    -   `ImageBitmap`\n    -   `ArrayBuffer`\n\n-   The implementation **can** handle circular references.\n\n-   If a `Number`, `String`, or `Boolean` object is encountered, the value is cloned as a **primitive**. This behavior is intentional. The implementation is opinionated in wanting to **avoid** creating `numbers`, `strings`, and `booleans` via the `new` operator and a constructor.\n\n-   For `objects`, the implementation **only** copies `enumerable` keys and their associated property descriptors.\n\n-   The implementation **only** checks whether basic `Objects`, `Arrays`, and class instances are `extensible`, `sealed`, and/or `frozen`.\n\n-   `functions` are **not** cloned; their reference is copied.\n\n-   The implementation supports custom [`error`][mdn-error] types which are [`Error`][mdn-error] instances (e.g., ES2015 subclasses).\n\n-   Support for copying class instances is inherently **fragile**. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This stated, basic copying of class instances is supported. Provided an environment which supports ES5, the implementation is greedy and performs a deep clone of any arbitrary class instance and its properties. The implementation assumes that the concept of `level` applies only to the class instance reference, but not to its internal state.\n\n    <!-- eslint-disable no-underscore-dangle -->\n\n    ```javascript\n    function Foo() {\n        this._data = [ 1, 2, 3, 4 ];\n        this._name = 'bar';\n        return this;\n    }\n\n    var foo1 = new Foo();\n    var foo2 = copy( foo1 );\n\n    var bool = ( foo1._name === foo2._name );\n    // returns true\n\n    bool = ( foo1._data === foo2._data );\n    // returns false\n\n    bool = ( foo1._data[0] === foo2._data[0] );\n    // returns true\n    ```\n\n</section>\n\n<!-- /.notes -->\n\n<section class=\"examples\">\n\n## Examples\n\n<!-- eslint no-undef: \"error\" -->\n\n```javascript\nvar randu = require( '@stdlib/random-base-randu' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar copy = require( '@stdlib/utils-copy' );\n\nvar arr = [\n    {\n        'x': new Date(),\n        'y': [ randu(), randu() ],\n        'z': new Int32Array( [ 1, 2, 3, 4 ] ),\n        'label': 'Beep'\n    },\n    {\n        'x': new Date(),\n        'y': [ randu(), randu() ],\n        'z': new Int32Array( [ 3, 1, 2, 4 ] ),\n        'label': 'Boop'\n    }\n];\n\n// Perform a full deep copy:\nvar out = copy( arr );\n\nvar bool = ( arr[ 0 ] === out[ 0 ] );\n// returns false\n\nbool = ( arr[ 1 ].y === out[ 1 ].y );\n// returns false\n\n// Perform a shallow copy:\nout = copy( arr, 1 );\n\nbool = ( arr[ 0 ] === out[ 0 ] );\n// returns true\n\nbool = ( arr[ 1 ].z === out[ 1 ].z );\n// returns true\n```\n\n</section>\n\n<!-- /.examples -->\n\n<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->\n\n<section class=\"related\">\n\n* * *\n\n## See Also\n\n-   <span class=\"package-name\">[`@stdlib/utils-merge`][@stdlib/utils/merge]</span><span class=\"delimiter\">: </span><span class=\"description\">merge and extend objects.</span>\n\n</section>\n\n<!-- /.related -->\n\n<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n\n<section class=\"main-repo\" >\n\n* * *\n\n## Notice\n\nThis package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.\n\nFor more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].\n\n#### Community\n\n[![Chat][chat-image]][chat-url]\n\n---\n\n## License\n\nSee [LICENSE][stdlib-license].\n\n\n## Copyright\n\nCopyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].\n\n</section>\n\n<!-- /.stdlib -->\n\n<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n<section class=\"links\">\n\n[npm-image]: http://img.shields.io/npm/v/@stdlib/utils-copy.svg\n[npm-url]: https://npmjs.org/package/@stdlib/utils-copy\n\n[test-image]: https://github.com/stdlib-js/utils-copy/actions/workflows/test.yml/badge.svg?branch=v0.2.3\n[test-url]: https://github.com/stdlib-js/utils-copy/actions/workflows/test.yml?query=branch:v0.2.3\n\n[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-copy/main.svg\n[coverage-url]: https://codecov.io/github/stdlib-js/utils-copy?branch=main\n\n<!--\n\n[dependencies-image]: https://img.shields.io/david/stdlib-js/utils-copy.svg\n[dependencies-url]: https://david-dm.org/stdlib-js/utils-copy/main\n\n-->\n\n[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg\n[chat-url]: https://stdlib.zulipchat.com\n\n[stdlib]: https://github.com/stdlib-js/stdlib\n\n[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors\n\n[umd]: https://github.com/umdjs/umd\n[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\n\n[deno-url]: https://github.com/stdlib-js/utils-copy/tree/deno\n[deno-readme]: https://github.com/stdlib-js/utils-copy/blob/deno/README.md\n[umd-url]: https://github.com/stdlib-js/utils-copy/tree/umd\n[umd-readme]: https://github.com/stdlib-js/utils-copy/blob/umd/README.md\n[esm-url]: https://github.com/stdlib-js/utils-copy/tree/esm\n[esm-readme]: https://github.com/stdlib-js/utils-copy/blob/esm/README.md\n[branches-url]: https://github.com/stdlib-js/utils-copy/blob/main/branches.md\n\n[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-copy/main/LICENSE\n\n[mdn-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error\n\n[mdn-type-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError\n\n[mdn-syntax-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError\n\n[mdn-range-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError\n\n[mdn-reference-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError\n\n[mdn-uri-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError\n\n[mdn-eval-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError\n\n[node-system-error]: https://nodejs.org/api/errors.html#errors_class_system_error\n\n[node-buffer]: http://nodejs.org/api/buffer.html\n\n<!-- <related-links> -->\n\n[@stdlib/utils/merge]: https://www.npmjs.com/package/@stdlib/utils-merge\n\n<!-- </related-links> -->\n\n</section>\n\n<!-- /.links -->\n","publish_time":1770525483987,"_cnpm_publish_time":1770525483987,"dist-tags":{"latest":"0.2.3"}}