copy-to
copy an object's properties to another object
Last updated 6 years ago by dead_horse .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install copy-to 
SYNC missed versions from official npm registry.

copy-to

Build Status

copy an object's properties to another one, include propertiy, getter and setter.

Install

npm install copy-to

Usage

copy(src).to(des);
copy(src).toCover(des);
copy(src).override(des);

copy(src).pick('proName1', 'proName2').to(des);
copy(src).pick('proName1', 'proName2').toCover(des);
copy(src).pick('proName1', 'proName2').override(des);

copy(src).and(other).to(des);
copy(src).and(other).toCover(des);
copy(src).and(second).and(third).to(des);

copy(src).and(other).pick('proName1', 'proName2').to(des);
copy(src).and(other).pick('proName1', 'proName2').toCover(des);
copy(src).and(second).and(third).pick('proName1', 'proName2').to(des);

It won't copy access(getter / setter) by default, if you want to copy them, please use:

copy(src).withAccess().and(other).to(des);

Example

var copy = require('copy-to');

var src = {
  _name: 'foo',
  set name(val) {
    this._name = val;
  },
  get name() {
    return this._name;
  },
  show: function () {
    console.log(this._name);
  }
};

var des = {
  _name: 'bar'
};

copy(src).to(des);
copy(src).toCover(des);
copy(src).pick('_name', 'name').to(des);
copy(src).pick('_name', 'name').toCover(des);

License

MIT

Current Tags

  • 2.0.1                                ...           latest (6 years ago)

7 Versions

  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 605
This Week 12,110
This Month 123,640
Last Day 11,505
Last Week 65,198
Last Month 280,975
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |