githubEdit

shallow-clone

Make a shallow clone of an object, array or primitive.

Install

Install with npmarrow-up-right

$ npm i shallow-clone --save

Usage

var clone = require('shallow-clone');

shallow clones arrays

The array itself is cloned, but not the elements of the array. So any objects in the array will still not be cloned (e.g. they will be the same object as in the orginal array).

var arr = [{ 'a': 0 }, { 'b': 1 }]
var foo = clone(arr);
// foo =>  [{ 'a': 0 }, { 'b': 1 }]

// array is cloned
assert.equal(actual === expected, false);

// array elements are not
assert.deepEqual(actual[0], expected[0]); // true

returns primitives as-is

shallow clone a regex

shallow clone an object

Running tests

Install dev dependencies:

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issuearrow-up-right

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cliarrow-up-right on August 10, 2015.

Last updated