3 [![build status](https://secure.travis-ci.org/pvorb/node-clone.png)](http://travis-ci.org/pvorb/node-clone)
5 [![info badge](https://nodei.co/npm/clone.png?downloads=true&downloadRank=true&stars=true)](http://npm-stat.com/charts.html?package=clone)
7 offers foolproof _deep cloning_ of objects, arrays, numbers, strings etc. in JavaScript.
14 (It also works with browserify, ender or standalone.)
20 var clone = require('clone');
24 a = { foo: { bar: 'baz' } }; // initial value of a
26 b = clone(a); // clone a -> b
27 a.foo.bar = 'foo'; // change a
29 console.log(a); // show a
30 console.log(b); // show b
36 { foo: { bar: 'foo' } }
37 { foo: { bar: 'baz' } }
40 **clone** masters cloning simple objects (even with custom prototype), arrays,
41 Date objects, and RegExp objects. Everything is cloned recursively, so that you
42 can clone dates in arrays in objects, for example.
47 `clone(val, circular, depth)`
49 * `val` -- the value that you want to clone, any type allowed
50 * `circular` -- boolean
52 Call `clone` with `circular` set to `false` if you are certain that `obj`
53 contains no circular references. This will give better performance if needed.
54 There is no error if `undefined` or `null` is passed as `obj`.
55 * `depth` -- depth to which the object is to be cloned (optional,
58 `clone.clonePrototype(obj)`
60 * `obj` -- the object that you want to clone
62 Does a prototype clone as
63 [described by Oran Looney](http://oranlooney.com/functional-javascript/).
66 ## Circular References
71 a = { hello: 'world' };
82 { hello: "world", myself: [Circular] }
85 So, `b.myself` points to `b`, not `a`. Neat!
95 Some special objects like a socket or `process.stdout`/`stderr` are known to not
96 be cloneable. If you find other objects that cannot be cloned, please [open an
97 issue](https://github.com/pvorb/node-clone/issues/new).
102 If you encounter any bugs or issues, feel free to [open an issue at
103 github](https://github.com/pvorb/node-clone/issues) or send me an email to
104 <paul@vorba.ch>. I also always like to hear from you, if you’re using my code.
108 Copyright © 2011-2015 [Paul Vorbach](http://paul.vorba.ch/) and
109 [contributors](https://github.com/pvorb/node-clone/graphs/contributors).
111 Permission is hereby granted, free of charge, to any person obtaining a copy of
112 this software and associated documentation files (the “Software”), to deal in
113 the Software without restriction, including without limitation the rights to
114 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
115 the Software, and to permit persons to whom the Software is furnished to do so,
116 subject to the following conditions:
118 The above copyright notice and this permission notice shall be included in all
119 copies or substantial portions of the Software.
121 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
122 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
123 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
124 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
125 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OUT OF OR IN CONNECTION WITH THE
126 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.