{"_id":"utils-copy","_rev":"4086957","name":"utils-copy","description":"Copy or deep clone a value to an arbitrary depth.","dist-tags":{"latest":"1.1.1"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"time":{"modified":"2025-12-02T22:11:33.000Z","created":"2015-03-05T09:19:11.465Z","1.1.1":"2016-03-01T23:32:00.983Z","1.1.0":"2015-12-30T11:55:34.731Z","1.0.0":"2015-03-05T09:19:31.204Z","0.0.0":"2015-03-05T09:19:11.465Z"},"users":{},"author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"repository":{"type":"git","url":"git://github.com/kgryte/utils-copy.git"},"versions":{"1.1.1":{"name":"utils-copy","version":"1.1.1","description":"Copy or deep clone a value to an arbitrary depth.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"if [ \"${TRAVIS}\" ]; then npm run test-ci; else npm run test-local; fi","test-local":"tape \"./test/*.js\" | tap-spec","test-ci":"npm run test-local && xvfb-run npm run test-browsers","test-cov":"istanbul cover --dir ./reports/coverage --report lcov tape -- \"./test/*.js\"","test-browsers":"browserify ./test/*.js | testling | tap-spec","coverage":"istanbul cover --dir ./reports/codecov/coverage --report lcovonly tape -- \"./test/*.js\" && cat ./reports/codecov/coverage/lcov.info | codecov && rm -rf ./reports/codecov"},"main":"./lib","repository":{"type":"git","url":"git://github.com/kgryte/utils-copy.git"},"keywords":["utilities","utils","util","copy","clone","deep","deepcopy","deepclone","shallow","shallowcopy","array","object","date","regexp","typed array","error","set","map","cp"],"bugs":{"url":"https://github.com/kgryte/utils-copy/issues"},"dependencies":{"const-pinf-float64":"^1.0.0","object-keys":"^1.0.9","type-name":"^2.0.0","utils-copy-error":"^1.0.0","utils-indexof":"^1.0.0","utils-regex-from-string":"^1.0.0","validate.io-array":"^1.0.3","validate.io-buffer":"^1.0.1","validate.io-nonnegative-integer":"^1.0.0"},"devDependencies":{"browserify":"13.x.x","chai":"3.x.x","codecov":"1.x.x","istanbul":"^0.4.1","jshint":"2.x.x","jshint-stylish":"2.x.x","tap-spec":"4.x.x","tape":"4.x.x","testling":"1.x.x"},"testling":{"files":["test/*.js"],"browsers":["iexplore/6.0..latest","firefox/3.0..latest","firefox/nightly","chrome/4.0..latest","chrome/canary","opera/10.0..latest","opera/next","safari/4.0..latest","ipad/6.0..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"license":"MIT","gitHead":"142f520f356ce338168b7888a73fc36b4b525995","homepage":"https://github.com/kgryte/utils-copy#readme","_id":"utils-copy@1.1.1","_shasum":"6e2b97982aa8cd73e1182a3e6f8bec3c0f4058a7","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.3","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"dist":{"shasum":"6e2b97982aa8cd73e1182a3e6f8bec3c0f4058a7","size":5961,"noattachment":false,"key":"/utils-copy/-/utils-copy-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/utils-copy/download/utils-copy-1.1.1.tgz"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/utils-copy-1.1.1.tgz_1456875118435_0.39546461147256196"},"directories":{},"publish_time":1456875120983,"_hasShrinkwrap":false,"_cnpm_publish_time":1456875120983,"_cnpmcore_publish_time":"2021-12-17T00:58:15.618Z"},"1.1.0":{"name":"utils-copy","version":"1.1.0","description":"Copy or deep clone a value to an arbitrary depth.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"if [ \"${TRAVIS}\" ]; then npm run test-ci; else npm run test-local; fi","test-local":"tape \"./test/*.js\" | tap-spec","test-ci":"npm run test-local && xvfb-run npm run test-browsers","test-cov":"istanbul cover --dir ./reports/coverage --report lcov tape -- \"./test/*.js\"","test-browsers":"browserify ./test/*.js | testling | tap-spec","coverage":"istanbul cover --dir ./reports/codecov/coverage --report lcovonly tape -- \"./test/*.js\" && cat ./reports/codecov/coverage/lcov.info | codecov && rm -rf ./reports/codecov"},"main":"./lib","repository":{"type":"git","url":"git://github.com/kgryte/utils-copy.git"},"keywords":["utilities","utils","util","copy","clone","deep","deepcopy","deepclone","shallow","shallowcopy","array","object","date","regexp","typed array","error","set","map","cp"],"bugs":{"url":"https://github.com/kgryte/utils-copy/issues"},"dependencies":{"object-keys":"^1.0.9","type-name":"^1.1.0","utils-copy-error":"^1.0.0","utils-regex-from-string":"^1.0.0","validate.io-array":"^1.0.3","validate.io-buffer":"^1.0.1","validate.io-nonnegative-integer":"^1.0.0"},"devDependencies":{"browserify":"12.x.x","chai":"^3.4.1","codecov.io":"^0.1.5","istanbul":"^0.4.1","jshint":"2.x.x","jshint-stylish":"2.x.x","tap-spec":"4.x.x","tape":"4.x.x","testling":"1.x.x"},"testling":{"files":["test/*.js"],"browsers":["iexplore/6.0..latest","firefox/3.0..latest","firefox/nightly","chrome/4.0..latest","chrome/canary","opera/10.0..latest","opera/next","safari/4.0..latest","ipad/6.0..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"license":"MIT","gitHead":"350491e1fd91ad23179e5a3a78a9ab35a7f43ab2","homepage":"https://github.com/kgryte/utils-copy#readme","_id":"utils-copy@1.1.0","_shasum":"488f7f9cdb4930ad5caa8124f7acc1e6b334d478","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.3","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"dist":{"shasum":"488f7f9cdb4930ad5caa8124f7acc1e6b334d478","size":6216,"noattachment":false,"key":"/utils-copy/-/utils-copy-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/utils-copy/download/utils-copy-1.1.0.tgz"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"directories":{},"publish_time":1451476534731,"_hasShrinkwrap":false,"_cnpm_publish_time":1451476534731,"_cnpmcore_publish_time":"2021-12-17T00:58:15.873Z"},"1.0.0":{"name":"utils-copy","version":"1.0.0","description":"Copy or deep clone a value to an arbitrary depth.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/kgryte/utils-copy.git"},"keywords":["utilities","utils","util","copy","clone","deep","deepcopy","deepclone","shallow","shallowcopy","array","object","date","regexp"],"bugs":{"url":"https://github.com/kgryte/utils-copy/issues"},"dependencies":{"type-name":"^1.0.1","validate.io-array":"^1.0.3","validate.io-buffer":"^1.0.0","validate.io-nonnegative-integer":"^1.0.0"},"devDependencies":{"chai":"2.x.x","mocha":"2.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"2.x.x","jshint-stylish":"^1.0.0"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"9cbb3195b2b3f96a29c5a130260bdbe99d89c347","homepage":"https://github.com/kgryte/utils-copy","_id":"utils-copy@1.0.0","_shasum":"f5a1ec47b36aec4e0c39e366aef09a1f61dbe3c8","_from":".","_npmVersion":"1.5.0-alpha-1","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"dist":{"shasum":"f5a1ec47b36aec4e0c39e366aef09a1f61dbe3c8","size":5923,"noattachment":false,"key":"/utils-copy/-/utils-copy-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/utils-copy/download/utils-copy-1.0.0.tgz"},"directories":{},"publish_time":1425547171204,"_hasShrinkwrap":false,"_cnpm_publish_time":1425547171204,"_cnpmcore_publish_time":"2021-12-17T00:58:16.123Z"},"0.0.0":{"name":"utils-copy","version":"0.0.0","description":"Copy or deep clone a value to an arbitrary depth.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/kgryte/utils-copy.git"},"keywords":["utilities","utils","util","copy","clone","deep","deepcopy","deepclone","shallow","shallowcopy","array","object","date","regexp"],"bugs":{"url":"https://github.com/kgryte/utils-copy/issues"},"dependencies":{"type-name":"^1.0.1","validate.io-array":"^1.0.3","validate.io-buffer":"^1.0.0","validate.io-nonnegative-integer":"^1.0.0"},"devDependencies":{"chai":"2.x.x","mocha":"2.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"2.x.x","jshint-stylish":"^1.0.0"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"6d80bebeb8e9e92f03de127e8e65182ce81b52d6","homepage":"https://github.com/kgryte/utils-copy","_id":"utils-copy@0.0.0","_shasum":"4f6fd8c4755268b4db4a6c35adcb579744189e43","_from":".","_npmVersion":"1.5.0-alpha-1","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"dist":{"shasum":"4f6fd8c4755268b4db4a6c35adcb579744189e43","size":5922,"noattachment":false,"key":"/utils-copy/-/utils-copy-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/utils-copy/download/utils-copy-0.0.0.tgz"},"directories":{},"publish_time":1425547151465,"_hasShrinkwrap":false,"_cnpm_publish_time":1425547151465,"_cnpmcore_publish_time":"2021-12-17T00:58:16.320Z"}},"readme":"Copy\n===\n[![NPM version][npm-image]][npm-url] [![Build Status][build-image]][build-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\n## Installation\n\n``` bash\n$ npm install utils-copy\n```\n\n\n## Usage\n\n``` javascript\nvar cp = require( 'utils-copy' );\n```\n\n#### cp( value[, level] )\n\nCopy or deep clone a `value` to an arbitrary depth. The `function` accepts both `objects` and `primitives`.\n\n``` javascript\nvar value, copy;\n\n// Primitives...\nvalue = 'beep';\ncopy = cp( value );\n// returns 'beep'\n\n// Objects...\nvalue = [{'a':1,'b':true,'c':[1,2,3]}];\ncopy = cp( value );\n// returns [{'a':1,'b':true,'c':[1,2,3]}]\n\nconsole.log( value[0].c === copy[0].c );\n// returns false\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, copy;\n\nvalue = [{'a':1,'b':true,'c':[1,2,3]}];\n\n// Trivial case => return the same reference\ncopy = cp( value, 0 );\n// returns [{'a':1,'b':true,'c':[1,2,3]}]\n\nconsole.log( value[0] === copy[0] );\n// returns true\n\n// Shallow copy:\ncopy = cp( value, 1 );\n\nconsole.log( value[0] === copy[0] );\n// returns false\n\nconsole.log( value[0].c === copy[0].c );\n// returns true\n\n// Deep copy:\ncopy = cp( value, 2 );\n\nconsole.log( value[0].c === copy[0].c );\n// returns false\n```\n\n\n## Notes\n\n*\tList of __supported__ values/types:\n\t-\t`undefined`\n\t-\t`null`\n\t-\t`boolean`/`Boolean`\n\t-\t`string`/`String`\n\t-\t`number`/`Number`\n\t-\t`function`\n\t-\t`Object`\n\t-\t`Date`\n\t-\t`RegExp`\n\t- \t`Set`\n\t-\t`Map`\n\t-\t`Error`\n\t- \t`URIError`\n\t-\t`ReferenceError`\n\t-\t`SyntaxError`\n\t-\t`RangeError`\n\t-\t`EvalError`\n\t-\t`TypeError`\n\t-\t`Array`\n\t-\t`Int8Array`\n\t-\t`Uint8Array`\n\t-\t`Uint8ClampedArray`\n\t-\t`Init16Array`\n\t-\t`Uint16Array`\n\t-\t`Int32Array`\n\t-\t`Uint32Array`\n\t-\t`Float32Array`\n\t-\t`Float64Array`\n\t-\t`Buffer` ([Node.js][node-buffer])\n\n*\tList of __unsupported__ values/types:\n\t-\t`DOMElement`: to copy DOM elements, use `element.cloneNode()`.\n\t-\t`Symbol`\n\t-\t`WeakMap`\n\t-\t`WeakSet`\n\t-\t`Blob`\n\t- \t`File`\n\t-\t`FileList`\n\t-\t`ImageData`\n\t-\t`ImageBitmap`\n\t-\t`ArrayBuffer`\n\n*\tThe implementation __can__ handle circular references.\n*\tIf 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* \tFor `objects`, the implementation __only__ copies `enumerable` keys and their associated property descriptors.\n*\tThe implementation __only__ checks whether basic `Objects`, `Arrays`, and class instances are `extensible`, `sealed`, and/or `frozen`.\n*\t`functions` are __not__ cloned; their reference is copied.\n*\tSupport 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\t``` javascript\n\tfunction Foo() {\n\t\tthis._data = [ 1, 2, 3, 4 ];\n\t\tthis._name = 'bar';\n\t\treturn this;\n\t}\n\n\tvar foo = new Foo();\n\tvar fooey = cp( foo );\n\n\tconsole.log( foo._name === fooey._name );\n\t// returns true\n\n\tconsole.log( foo._data === fooey._data );\n\t// returns false\n\n\tconsole.log( foo._data[0] === fooey._data[0] );\n\t// returns true\n\t```\n\n\n## Examples\n\n``` javascript\nvar cp = require( 'utils-copy' );\n\nvar arr = [\n\t{\n\t\t'x': new Date(),\n\t\t'y': [Math.random(),Math.random()],\n\t\t'z': new Int32Array([1,2,3,4]),\n\t\t'label': 'Beep'\n\t},\n\t{\n\t\t'x': new Date(),\n\t\t'y': [Math.random(),Math.random()],\n\t\t'z': new Int32Array([3,1,2,4]),\n\t\t'label': 'Boop'\n\t}\n];\n\nvar copy = cp( arr );\n\nconsole.log( arr[ 0 ] === copy[ 0 ] );\n// returns false\n\nconsole.log( arr[ 1 ].y === copy[ 1 ].y );\n// returns false\n\n\ncopy = cp( arr, 1 );\n\nconsole.log( arr[ 0 ] === copy[ 0 ] );\n// returns true\n\nconsole.log( arr[ 1 ].z === copy[ 1 ].z );\n// returns true\n```\n\nTo run the example code from the top-level application directory,\n\n``` bash\n$ node ./examples/index.js\n```\n\n\n---\n## Tests\n\n### Unit\n\nThis repository uses [tape][tape] for unit tests. To run the tests, execute the following command in the top-level application directory:\n\n``` bash\n$ make test\n```\n\nAll new feature development should have corresponding unit tests to validate correct functionality.\n\n\n### Test Coverage\n\nThis repository uses [Istanbul][istanbul] as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-cov\n```\n\nIstanbul creates a `./reports/coverage` directory. To access an HTML version of the report,\n\n``` bash\n$ make view-cov\n```\n\n\n### Browser Support\n\nThis repository uses [Testling][testling] for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-browsers\n```\n\nTo view the tests in a local web browser,\n\n``` bash\n$ make view-browser-tests\n```\n\n<!-- [![browser support][browsers-image]][browsers-url] -->\n\n\n---\n## License\n\n[MIT license](http://opensource.org/licenses/MIT). \n\n\n## Copyright\n\nCopyright &copy; 2015-2016. Athan Reines.\n\n\n[npm-image]: http://img.shields.io/npm/v/utils-copy.svg\n[npm-url]: https://npmjs.org/package/utils-copy\n\n[build-image]: http://img.shields.io/travis/kgryte/utils-copy/master.svg\n[build-url]: https://travis-ci.org/kgryte/utils-copy\n\n[coverage-image]: https://img.shields.io/codecov/c/github/kgryte/utils-copy/master.svg\n[coverage-url]: https://codecov.io/github/kgryte/utils-copy?branch=master\n\n[dependencies-image]: http://img.shields.io/david/kgryte/utils-copy.svg\n[dependencies-url]: https://david-dm.org/kgryte/utils-copy\n\n[dev-dependencies-image]: http://img.shields.io/david/dev/kgryte/utils-copy.svg\n[dev-dependencies-url]: https://david-dm.org/dev/kgryte/utils-copy\n\n[github-issues-image]: http://img.shields.io/github/issues/kgryte/utils-copy.svg\n[github-issues-url]: https://github.com/kgryte/utils-copy/issues\n\n[browsers-image]: https://ci.testling.com/kgryte/utils-copy.png\n[browsers-url]: https://ci.testling.com/kgryte/utils-copy\n\n[tape]: https://github.com/substack/tape\n[istanbul]: https://github.com/gotwarlost/istanbul\n[testling]: https://ci.testling.com\n\n[node-buffer]: http://nodejs.org/api/buffer.html\n","_attachments":{},"homepage":"https://github.com/kgryte/utils-copy#readme","bugs":{"url":"https://github.com/kgryte/utils-copy/issues"},"license":"MIT"}