clone-shallow
Shallow clone objects and arrays, or return primitive values directly.
Last updated 12 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install clone-shallow 
SYNC missed versions from official npm registry.

clone-shallow NPM version

Shallow clone objects and arrays, or return primitive values directly.

Install

Install with npm:

npm i clone-shallow --save-dev

Usage

clone(value);
  • value {*} The value to clone.
  • return {*} The cloned value.

Example

Arrays:

var a = ['a', 'b', 'c'];
var b = clone(a);
a = a.concat('new');

console.log('a:', a);
//=> a: [ 'a', 'b', 'c', 'new' ]

console.log('b:', b);
//=> b: [ 'a', 'b', 'c' ]

Objects:

var extend = require('xtend');
var a = {foo: 'alpha', bar: 'beta', baz: 'gamma'};
var b = cloneObject(a);
a = extend(a, {quux: 'delta'});

console.log('a:', a);
//=> a: { foo: 'alpha', bar: 'beta', baz: 'gamma', quux: 'delta' }
console.log('b:', b);
//=> b: { foo: 'alpha', bar: 'beta', baz: 'gamma' }

Also see:

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on June 30, 2014.

Current Tags

  • 0.1.1                                ...           latest (12 years ago)

2 Versions

  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |