https://github.com/node-modules/copy-to
copy an object's properties to another one
https://github.com/node-modules/copy-to
Last synced: 11 days ago
JSON representation
copy an object's properties to another one
- Host: GitHub
- URL: https://github.com/node-modules/copy-to
- Owner: node-modules
- License: mit
- Created: 2014-03-26T14:34:50.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T04:37:22.000Z (over 3 years ago)
- Last Synced: 2025-05-23T02:42:43.771Z (about 1 month ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 41
- Watchers: 15
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
copy-to
=======[](https://travis-ci.org/node-modules/copy-to)
copy an object's properties to another one, include propertiy, getter and setter.
## Install
```
npm install copy-to
```## Usage
```js
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:
```js
copy(src).withAccess().and(other).to(des);
```## Example
```js
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