pax_global_header00006660000000000000000000000064126045052200014506gustar00rootroot0000000000000052 comment=b2a12c4bbbcc1dfea2a9603ba8d1ea979503dbb1 fill-keys-1.0.2/000077500000000000000000000000001260450522000134055ustar00rootroot00000000000000fill-keys-1.0.2/.editorconfig000066400000000000000000000002741260450522000160650ustar00rootroot00000000000000root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false fill-keys-1.0.2/.gitattributes000066400000000000000000000000141260450522000162730ustar00rootroot00000000000000* text=auto fill-keys-1.0.2/.gitignore000066400000000000000000000000151260450522000153710ustar00rootroot00000000000000node_modules fill-keys-1.0.2/.travis.yml000066400000000000000000000000421260450522000155120ustar00rootroot00000000000000language: node_js node_js: - iojs fill-keys-1.0.2/index.js000066400000000000000000000017071260450522000150570ustar00rootroot00000000000000'use strict' var mergeDescriptors = require('merge-descriptors') var isObject = require('is-object') var hasOwnProperty = Object.prototype.hasOwnProperty function fill (destination, source, merge) { if (destination && (isObject(source) || isFunction(source))) { merge(destination, source, false) if (isFunction(destination) && isFunction(source) && source.prototype) { merge(destination.prototype, source.prototype, false) } } return destination } exports = module.exports = function fillKeys (destination, source) { return fill(destination, source, mergeDescriptors) } exports.es3 = function fillKeysEs3 (destination, source) { return fill(destination, source, es3Merge) } function es3Merge (destination, source) { for (var key in source) { if (!hasOwnProperty.call(destination, key)) { destination[key] = source[key] } } return destination } function isFunction (value) { return typeof value === 'function' } fill-keys-1.0.2/license000066400000000000000000000021271260450522000147540ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Ben Drucker (bendrucker.me) 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. fill-keys-1.0.2/package.json000066400000000000000000000012601260450522000156720ustar00rootroot00000000000000{ "name": "fill-keys", "main": "index.js", "version": "1.0.2", "description": "Fill keys in a destination that are defined on the source", "license": "MIT", "repository": "bendrucker/fill-keys", "author": { "name": "Ben Drucker", "email": "bvdrucker@gmail.com", "url": "bendrucker.me" }, "engines": { "node": ">=0.10.0" }, "scripts": { "test": "standard && tape test.js" }, "keywords": [ "keys", "object", "copy" ], "dependencies": { "is-object": "~1.0.1", "merge-descriptors": "~1.0.0" }, "devDependencies": { "tape": "^4.0.0", "standard": "^4.0.0" }, "files": [ "index.js", "readme.md" ] } fill-keys-1.0.2/readme.md000066400000000000000000000021551260450522000151670ustar00rootroot00000000000000# fill-keys [![Build Status](https://travis-ci.org/bendrucker/fill-keys.svg?branch=master)](https://travis-ci.org/bendrucker/fill-keys) > Fill keys in a destination that are defined on the source. Copies descriptors so properties like `enumerable` will persist. ## Install ``` $ npm install --save fill-keys ``` ## Usage ```js var fillKeys = require('fill-keys'); fillKeys(destination, source); //=> missing destination keys in source are copied ``` fill-keys will copy descriptors. It will also copy the `source.prototype` properties onto `destination.prototype` if both `destination` and `source` are functions. ## API #### `fillKeys(destination, source)` -> `destination` #### `destination` *Required* Type: `any` The destination object where keys from `source` will be added. #### source *Required* Type: `any` The source object from which to copy properties. #### `fillKeys.es3(destination, source)` -> `destination` An ES3-compatible version of `fillKeys`. Behavior is identical but simple assignment is used instead of `Object.defineProperty`. ## License MIT © [Ben Drucker](http://bendrucker.me) fill-keys-1.0.2/test.js000066400000000000000000000023101260450522000147160ustar00rootroot00000000000000'use strict' var test = require('tape') var fillKeys = require('./') test('fill-keys', function (t) { t.test('es5', function (t) { run(fillKeys, t) var dest = {} fillKeys(dest, Object.defineProperty({}, 'foo', { enumerable: true })) t.ok(Object.getOwnPropertyDescriptor(dest, 'foo').enumerable, 'copies descriptor') t.end() }) t.test('es3', function (t) { run(fillKeys.es3, t) t.end() }) t.end() }) function run (fill, t) { t.deepEqual(fill({}, {foo: 'bar'}), {foo: 'bar'}, 'simple deep equality') let dest = {} fill(dest, {foo: 'bar'}) t.deepEqual(dest, {foo: 'bar'}, 'mutates dest') function sourceFn () {} function destFn () {} sourceFn.prototype = {foo: 'bar'} t.deepEqual(fill(destFn, sourceFn).prototype, {foo: 'bar'}, 'fills prototype') t.equal(fill(undefined, undefined), undefined, 'both') t.deepEqual(fill({}, undefined), {}, 'source undefined') t.deepEqual(fill(undefined, {}), undefined, 'dest undefined') t.deepEqual(fill(Object.create(null), {foo: 'bar'}), {foo: 'bar'}, 'destination obj has no proto') } test('fn with no prototype', function (t) { t.doesNotThrow(fillKeys.bind(null, function () {}, Date.now)) t.end() })