npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

clone-shallow

0.1.1

@jonschlinkert

npmHomeRepoSnykSocket
Downloads:10086
$ npm install clone-shallow
DailyWeeklyMonthlyYearly

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:

  • clone-array if you just need to clone arrays.
  • clone-object if you just need to clone objects.

Author

Jon Schlinkert

  • github/jonschlinkert
  • twitter/jonschlinkert

License

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


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