JSPM

copy-descriptor

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19526855
  • Score
    100M100P100Q223019F
  • License MIT

Copy a descriptor from object A to object B

Package Exports

  • copy-descriptor

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (copy-descriptor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

copy-descriptor NPM version Build Status

Copy a descriptor from object A to object B

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm i copy-descriptor --save

Usage

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

API

copy

Copy a descriptor from one object to another.

Params

  • receiver {Object}: The target object
  • provider {Object}: The provider object
  • from {String}: The key to copy on provider.
  • to {String}: Optionally specify a new key name to use.
  • returns {Object}

Example

function App() {
  this.cache = {};
}
App.prototype.set = function(key, val) {
  this.cache[key] = val;
  return this;
};
Object.defineProperty(App.prototype, 'count', {
  get: function() {
    return Object.keys(this.cache).length;
  }
});

copy(App.prototype, 'count', 'len');

// create an instance
var app = new App();

app.set('a', true);
app.set('b', true);
app.set('c', true);

console.log(app.count);
//=> 3
console.log(app.len);
//=> 3

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb on December 28, 2015.