pax_global_header00006660000000000000000000000064126470233300014512gustar00rootroot0000000000000052 comment=f26c49c3b423b0b2ac31f6e32a84e1632f2d7ac2 merge-descriptors-1.0.1/000077500000000000000000000000001264702333000151475ustar00rootroot00000000000000merge-descriptors-1.0.1/.gitignore000066400000000000000000000000461264702333000171370ustar00rootroot00000000000000coverage/ node_modules/ npm-debug.log merge-descriptors-1.0.1/.travis.yml000066400000000000000000000011601264702333000172560ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" - "0.12" - "1.8" - "2.5" - "3.3" - "4.2" - "5.4" sudo: false before_install: # Setup Node.js version-specific dependencies - test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul - test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul script: # Run test script, depending on istanbul install - "test ! -z $(npm -ps ls istanbul) || npm test" - "test -z $(npm -ps ls istanbul) || npm run-script test-ci" after_script: - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" merge-descriptors-1.0.1/HISTORY.md000066400000000000000000000005531264702333000166350ustar00rootroot000000000000001.0.1 / 2016-01-17 ================== * perf: enable strict mode 1.0.0 / 2015-03-01 ================== * Add option to only add new descriptors * Add simple argument validation * Add jsdoc to source file 0.0.2 / 2013-12-14 ================== * Move repository to `component` organization 0.0.1 / 2013-10-29 ================== * Initial release merge-descriptors-1.0.1/LICENSE000066400000000000000000000022171264702333000161560ustar00rootroot00000000000000(The MIT License) Copyright (c) 2013 Jonathan Ong Copyright (c) 2015 Douglas Christopher Wilson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. merge-descriptors-1.0.1/README.md000066400000000000000000000022751264702333000164340ustar00rootroot00000000000000# Merge Descriptors [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] Merge objects using descriptors. ```js var thing = { get name() { return 'jon' } } var animal = { } merge(animal, thing) animal.name === 'jon' ``` ## API ### merge(destination, source) Redefines `destination`'s descriptors with `source`'s. ### merge(destination, source, false) Defines `source`'s descriptors on `destination` if `destination` does not have a descriptor by the same name. ## License [MIT](LICENSE) [npm-image]: https://img.shields.io/npm/v/merge-descriptors.svg [npm-url]: https://npmjs.org/package/merge-descriptors [travis-image]: https://img.shields.io/travis/component/merge-descriptors/master.svg [travis-url]: https://travis-ci.org/component/merge-descriptors [coveralls-image]: https://img.shields.io/coveralls/component/merge-descriptors/master.svg [coveralls-url]: https://coveralls.io/r/component/merge-descriptors?branch=master [downloads-image]: https://img.shields.io/npm/dm/merge-descriptors.svg [downloads-url]: https://npmjs.org/package/merge-descriptors merge-descriptors-1.0.1/component.json000066400000000000000000000003141264702333000200420ustar00rootroot00000000000000{ "name": "merge-descriptors", "description": "Merge objects using descriptors", "version": "1.0.1", "scripts": [ "index.js" ], "repo": "component/merge-descriptors", "license": "MIT" } merge-descriptors-1.0.1/index.js000066400000000000000000000022771264702333000166240ustar00rootroot00000000000000/*! * merge-descriptors * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module exports. * @public */ module.exports = merge /** * Module variables. * @private */ var hasOwnProperty = Object.prototype.hasOwnProperty /** * Merge the property descriptors of `src` into `dest` * * @param {object} dest Object to add descriptors to * @param {object} src Object to clone descriptors from * @param {boolean} [redefine=true] Redefine `dest` properties with `src` properties * @returns {object} Reference to dest * @public */ function merge(dest, src, redefine) { if (!dest) { throw new TypeError('argument dest is required') } if (!src) { throw new TypeError('argument src is required') } if (redefine === undefined) { // Default to true redefine = true } Object.getOwnPropertyNames(src).forEach(function forEachOwnPropertyName(name) { if (!redefine && hasOwnProperty.call(dest, name)) { // Skip desriptor return } // Copy descriptor var descriptor = Object.getOwnPropertyDescriptor(src, name) Object.defineProperty(dest, name, descriptor) }) return dest } merge-descriptors-1.0.1/package.json000066400000000000000000000016431264702333000174410ustar00rootroot00000000000000{ "name": "merge-descriptors", "description": "Merge objects using descriptors", "version": "1.0.1", "author": { "name": "Jonathan Ong", "email": "me@jongleberry.com", "url": "http://jongleberry.com", "twitter": "https://twitter.com/jongleberry" }, "contributors": [ "Douglas Christopher Wilson ", "Mike Grabowski " ], "license": "MIT", "repository": "component/merge-descriptors", "devDependencies": { "istanbul": "0.4.1", "mocha": "1.21.5" }, "files": [ "HISTORY.md", "LICENSE", "README.md", "index.js" ], "scripts": { "test": "mocha --reporter spec --bail --check-leaks test/", "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/" } } merge-descriptors-1.0.1/test/000077500000000000000000000000001264702333000161265ustar00rootroot00000000000000merge-descriptors-1.0.1/test/merge.js000066400000000000000000000072061264702333000175700ustar00rootroot00000000000000var assert = require('assert') var merge = require('..') var source = { name: 'John', surname: 'Doe' }; Object.defineProperty(source, 'fullName', { get: function() { return this.name + ' ' + this.surname; } }); describe('merge(dest, src)', function () { describe('arguments', function () { describe('dest', function () { it('should be required', function () { assert.throws(merge.bind(null, undefined), 'argument dest is required') }) it('should reject null', function () { assert.throws(merge.bind(null, null), 'argument dest is required') }) }) describe('src', function () { it('should be required', function () { assert.throws(merge.bind(null, {}, undefined), 'argument src is required') }) it('should reject null', function () { assert.throws(merge.bind(null, {}, null), 'argument dest is required') }) }) }) describe('when merging objects', function () { it('should copy property descriptors from src to dest', function () { var dest = {} var src = {} Object.defineProperty(src, 'name', { value: 'TJ' }) assert.ok(!dest.hasOwnProperty('name')) merge(dest, src) assert.ok(dest.hasOwnProperty('name')) assert.ok(Object.getOwnPropertyDescriptor(dest, 'name')) assert.equal(Object.getOwnPropertyDescriptor(dest, 'name').value, 'TJ') }) describe('when property exists in src', function () { it('should redefine when configurable', function () { var dest = {} var src = {} Object.defineProperty(dest, 'name', { configurable: true, value: 'TJ' }) Object.defineProperty(src, 'name', { value: 'fido' }) assert.ok(dest.hasOwnProperty('name')) assert.equal(Object.getOwnPropertyDescriptor(dest, 'name').value, 'TJ') assert.ok(src.hasOwnProperty('name')) assert.equal(Object.getOwnPropertyDescriptor(src, 'name').value, 'fido') merge(dest, src) assert.ok(dest.hasOwnProperty('name')) assert.ok(Object.getOwnPropertyDescriptor(dest, 'name')) assert.equal(Object.getOwnPropertyDescriptor(dest, 'name').value, 'fido') }) it('should error when non-configurable', function () { var dest = {} var src = {} Object.defineProperty(dest, 'name', { configurable: false, value: 'TJ' }) Object.defineProperty(src, 'name', { value: 'fido' }) assert.ok(dest.hasOwnProperty('name')) assert.equal(Object.getOwnPropertyDescriptor(dest, 'name').value, 'TJ') assert.ok(src.hasOwnProperty('name')) assert.equal(Object.getOwnPropertyDescriptor(src, 'name').value, 'fido') assert.throws(merge.bind(null, dest, src), /Cannot redefine property: name/) }) it('should skip when redefine is false', function () { var dest = {} var src = {} Object.defineProperty(dest, 'name', { configurable: true, value: 'TJ' }) Object.defineProperty(src, 'name', { value: 'fido' }) assert.ok(dest.hasOwnProperty('name')) assert.equal(Object.getOwnPropertyDescriptor(dest, 'name').value, 'TJ') assert.ok(src.hasOwnProperty('name')) assert.equal(Object.getOwnPropertyDescriptor(src, 'name').value, 'fido') merge(dest, src, false) assert.ok(dest.hasOwnProperty('name')) assert.ok(Object.getOwnPropertyDescriptor(dest, 'name')) assert.equal(Object.getOwnPropertyDescriptor(dest, 'name').value, 'TJ') }) }) }) })