pax_global_header00006660000000000000000000000064132047332340014513gustar00rootroot0000000000000052 comment=f80d616c7bb5ccdf63f5a11a24e3e51dfaf2e7a3 extend-shallow-3.0.1/000077500000000000000000000000001320473323400144525ustar00rootroot00000000000000extend-shallow-3.0.1/.editorconfig000066400000000000000000000004411320473323400171260ustar00rootroot00000000000000# http://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = false extend-shallow-3.0.1/.eslintrc.json000066400000000000000000000067751320473323400172650ustar00rootroot00000000000000{ "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } extend-shallow-3.0.1/.gitattributes000066400000000000000000000001771320473323400173520ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binaryextend-shallow-3.0.1/.gitignore000066400000000000000000000004461320473323400164460ustar00rootroot00000000000000# always ignore files *.DS_Store .idea *.sublime-* # test related, or directories generated by tests test/actual actual coverage .nyc* # npm node_modules npm-debug.log # yarn yarn.lock yarn-error.log # misc _gh_pages _draft _drafts bower_components vendor temp tmp TODO.md package-lock.jsonextend-shallow-3.0.1/.travis.yml000066400000000000000000000002141320473323400165600ustar00rootroot00000000000000sudo: false os: - linux - osx language: node_js node_js: - node - '9' - '8' - '7' - '6' - '5' - '4' - '0.12' - '0.10' extend-shallow-3.0.1/.verb.md000066400000000000000000000003421320473323400160070ustar00rootroot00000000000000## Usage ```js var extend = require('{%= name %}'); extend({a: 'b'}, {c: 'd'}) //=> {a: 'b', c: 'd'} ``` Pass an empty object to shallow clone: ```js var obj = {}; extend(obj, {a: 'b'}, {c: 'd'}) //=> {a: 'b', c: 'd'} ``` extend-shallow-3.0.1/LICENSE000066400000000000000000000021061320473323400154560ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2015, 2017, Jon Schlinkert. 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. extend-shallow-3.0.1/README.md000066400000000000000000000107651320473323400157420ustar00rootroot00000000000000# extend-shallow [![NPM version](https://img.shields.io/npm/v/extend-shallow.svg?style=flat)](https://www.npmjs.com/package/extend-shallow) [![NPM monthly downloads](https://img.shields.io/npm/dm/extend-shallow.svg?style=flat)](https://npmjs.org/package/extend-shallow) [![NPM total downloads](https://img.shields.io/npm/dt/extend-shallow.svg?style=flat)](https://npmjs.org/package/extend-shallow) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/extend-shallow.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/extend-shallow) > Extend an object with the properties of additional objects. node.js/javascript util. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save extend-shallow ``` ## Usage ```js var extend = require('extend-shallow'); extend({a: 'b'}, {c: 'd'}) //=> {a: 'b', c: 'd'} ``` Pass an empty object to shallow clone: ```js var obj = {}; extend(obj, {a: 'b'}, {c: 'd'}) //=> {a: 'b', c: 'd'} ``` ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh $ npm install && npm test ```
Building docs _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ```
### Related projects You might also be interested in these projects: * [extend-shallow](https://www.npmjs.com/package/extend-shallow): Extend an object with the properties of additional objects. node.js/javascript util. | [homepage](https://github.com/jonschlinkert/extend-shallow "Extend an object with the properties of additional objects. node.js/javascript util.") * [for-in](https://www.npmjs.com/package/for-in): Iterate over the own and inherited enumerable properties of an object, and return an object… [more](https://github.com/jonschlinkert/for-in) | [homepage](https://github.com/jonschlinkert/for-in "Iterate over the own and inherited enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js") * [for-own](https://www.npmjs.com/package/for-own): Iterate over the own enumerable properties of an object, and return an object with properties… [more](https://github.com/jonschlinkert/for-own) | [homepage](https://github.com/jonschlinkert/for-own "Iterate over the own enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js.") * [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.") * [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.") * [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.") ### Contributors | **Commits** | **Contributor** | | --- | --- | | 33 | [jonschlinkert](https://github.com/jonschlinkert) | | 1 | [pdehaan](https://github.com/pdehaan) | ### Author **Jon Schlinkert** * [github/jonschlinkert](https://github.com/jonschlinkert) * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) ### License Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 19, 2017._extend-shallow-3.0.1/benchmark/000077500000000000000000000000001320473323400164045ustar00rootroot00000000000000extend-shallow-3.0.1/benchmark/code/000077500000000000000000000000001320473323400173165ustar00rootroot00000000000000extend-shallow-3.0.1/benchmark/code/1-1-4.js000066400000000000000000000012531320473323400203140ustar00rootroot00000000000000'use strict'; var typeOf = require('kind-of'); /** * Expose `extend` */ module.exports = extend; /** * Extend `o` with properties of other `objects`. * * @param {Object} `o` The target object. Pass an empty object to shallow clone. * @param {Object} `objects` * @return {Object} */ function extend(o) { if (typeOf(o) !== 'object') { return {}; } var args = arguments; var len = args.length - 1; for (var i = 0; i < len; i++) { var obj = args[i + 1]; if (typeOf(obj) === 'object' && typeOf(obj) !== 'regexp') { for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } } return o; }; extend-shallow-3.0.1/benchmark/code/assign.js000066400000000000000000000006461320473323400211460ustar00rootroot00000000000000 var isObject = require('is-extendable'); module.exports = function extend(a, b) { if (!a) return {}; if (!b) return a; var len = arguments.length - 1, i = 1; while (len--) { var obj = arguments[i++]; if (isObject(obj)) { assign(a, obj); } } return a; }; function assign(o, obj) { for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } return o; } extend-shallow-3.0.1/benchmark/code/extend-shallow.js000066400000000000000000000000621320473323400226100ustar00rootroot00000000000000'use strict'; module.exports = require('../..'); extend-shallow-3.0.1/benchmark/code/for-arguments-in.js000066400000000000000000000005721320473323400230550ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) { o = {}; } var len = arguments.length; for (var i = 1; i < len; i++) { var obj = arguments[i]; if (isObject(obj)) { assign(o, obj); } } return o; }; function assign(a, b) { for (var key in b) { a[key] = b[key]; } } extend-shallow-3.0.1/benchmark/code/for-arguments.js000066400000000000000000000006371320473323400224530ustar00rootroot00000000000000'use strict'; var isObject = require('is-plain-object'); module.exports = function extend(o, objects) { if (!o || !objects) { return o || {}; } var len = arguments.length - 1; for (var i = 0; i < len; i++) { var obj = arguments[i + 1]; if (isObject(obj)) { for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } } return o; }; extend-shallow-3.0.1/benchmark/code/for-each.js000066400000000000000000000005701320473323400213420ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) {o = {};} var args = [].slice.call(arguments); args.forEach(function (obj) { if (isObject(obj)) { for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } }); return o; }; extend-shallow-3.0.1/benchmark/code/for-negative.js000066400000000000000000000006401320473323400222420ustar00rootroot00000000000000'use strict'; var slice = require('array-slice'); module.exports = function extend(o, objects) { if (o == null) { return {}; } if (objects == null) { return o; } var args = slice(arguments, 1); var len = args.length - 1; for (var i = len; i >= 0; i--) { var obj = args[i]; for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } return o; };extend-shallow-3.0.1/benchmark/code/for-own-lib.js000066400000000000000000000006371320473323400220150ustar00rootroot00000000000000'use strict'; var slice = require('array-slice'); var forOwn = require('for-own'); module.exports = function extend(o, objects) { if (o == null) { return {}; } if (objects == null) { return o; } var args = slice(arguments, 1); var len = args.length; for (var i = 0; i < len; i++) { var obj = args[i]; forOwn(obj, function (value, key) { this[key] = value; }, o); } return o; }; extend-shallow-3.0.1/benchmark/code/for-own-slice-call.js000066400000000000000000000006021320473323400232470ustar00rootroot00000000000000'use strict'; module.exports = function extend(o, objects) { if (o == null) { return {}; } if (objects == null) { return o; } var args = [].slice.call([], arguments, 1); var len = args.length; for (var i = 0; i < len; i++) { var obj = args[i]; for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } return o; }; extend-shallow-3.0.1/benchmark/code/for-own.js000066400000000000000000000006341320473323400212460ustar00rootroot00000000000000'use strict'; var slice = require('array-slice'); module.exports = function extend(o, objects) { if (o == null) { return {}; } if (objects == null) { return o; } var args = slice(arguments, 1); var len = args.length; for (var i = 0; i < len; i++) { var obj = args[i]; for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } return o; }; extend-shallow-3.0.1/benchmark/code/for-prop-in.js000066400000000000000000000005551320473323400220310ustar00rootroot00000000000000'use strict'; var slice = require('array-slice'); module.exports = function extend(o, objects) { if (o == null) { return {}; } if (objects == null) { return o; } var args = slice(arguments, 1); var len = args.length; for (var i = 0; i < len; i++) { var obj = args[i]; for (var key in obj) { o[key] = obj[key]; } } return o; }; extend-shallow-3.0.1/benchmark/code/for-slice-call-in.js000066400000000000000000000005231320473323400230540ustar00rootroot00000000000000'use strict'; module.exports = function extend(o, objects) { if (o == null) { return {}; } if (objects == null) { return o; } var args = [].slice.call([], arguments, 1); var len = args.length; for (var i = 0; i < len; i++) { var obj = args[i]; for (var key in obj) { o[key] = obj[key]; } } return o; }; extend-shallow-3.0.1/benchmark/code/for.js000066400000000000000000000006101320473323400204370ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) {o = {};} var len = arguments.length; for (var i = 1; i < len; i++) { var obj = arguments[i]; if (isObject(obj)) { for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } } return o; }; extend-shallow-3.0.1/benchmark/code/object-assign.js000066400000000000000000000000721320473323400224030ustar00rootroot00000000000000'use strict'; module.exports = require('object-assign'); extend-shallow-3.0.1/benchmark/code/reduce.js000066400000000000000000000006171320473323400211270ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) {o = {};} var args = [].slice.call(arguments, 1); return args.reduce(function (acc, val, i) { if (isObject(val)) { for (var key in val) { if (val.hasOwnProperty(key)) { acc[key] = val[key]; } } } return acc; }, o); }; extend-shallow-3.0.1/benchmark/code/while-arguments-in.js000066400000000000000000000005221320473323400233720ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) { o = {}; } var len = arguments.length, i = 1; while (len--) { var obj = arguments[i++]; if (isObject(obj)) { for (var key in obj) { o[key] = obj[key]; } } } return o; }; extend-shallow-3.0.1/benchmark/code/while-for-own.js000066400000000000000000000007571320473323400223620ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) {o = {};} var len = arguments.length; var i = 1; while (len--) { var obj = arguments[i++]; if (isObject(obj)) { var keys = Object.keys(obj); var klen = keys.length; for (var j = 0; j < klen; j++) { var key = keys[j]; if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } } return o; }; extend-shallow-3.0.1/benchmark/code/while-for.js000066400000000000000000000006741320473323400215570ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) {o = {};} var len = arguments.length; var i = 1; while (len--) { var obj = arguments[i++]; if (isObject(obj)) { var keys = Object.keys(obj); var klen = keys.length; for (var j = 0; j < klen; j++) { var key = keys[j]; o[key] = obj[key]; } } } return o; }; extend-shallow-3.0.1/benchmark/code/while-while.js000066400000000000000000000006651320473323400221010ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) {o = {};} var len = arguments.length; var i = 1; while (len--) { var obj = arguments[i++]; if (isObject(obj)) { var keys = Object.keys(obj); var klen = keys.length, j = 0; while (klen--) { var key = keys[j++]; o[key] = obj[key]; } } } return o; }; extend-shallow-3.0.1/benchmark/code/while-while2.js000066400000000000000000000006601320473323400221560ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = function extend(o, objects) { if (!isObject(o)) {o = {};} var len = arguments.length; var i = 1; while (len--) { var obj = arguments[i++]; if (isObject(obj)) { var keys = Object.keys(obj); var klen = keys.length, j = 0; var key; while (key = keys[j++]) { o[key] = obj[key]; } } } return o; }; extend-shallow-3.0.1/benchmark/code/while.js000066400000000000000000000006211320473323400207630ustar00rootroot00000000000000'use strict'; var isObject = require('is-extendable'); module.exports = extend; function extend(o, objects) { if (!isObject(o)) { o = {}; } var len = arguments.length, i = 1; while (len--) { var obj = arguments[i++]; if (isObject(obj)) { for (var key in obj) { if (obj.hasOwnProperty(key)) { o[key] = obj[key]; } } } } return o; } extend-shallow-3.0.1/benchmark/fixtures/000077500000000000000000000000001320473323400202555ustar00rootroot00000000000000extend-shallow-3.0.1/benchmark/fixtures/basic.js000066400000000000000000000000611320473323400216710ustar00rootroot00000000000000module.exports = [{a: 'b'}, {c: 'd'}, {e: 'f'}]; extend-shallow-3.0.1/benchmark/fixtures/nested.js000066400000000000000000000002041320473323400220710ustar00rootroot00000000000000module.exports = [ {a: 'a', m: {x: 'x'}}, {b: 'b', m: {x: 'q'}}, {c: 'c', m: {y: 'y'}}, {d: 'd', m: {z: 'z'}}, {d: 'e'} ];extend-shallow-3.0.1/benchmark/fixtures/sparse.js000066400000000000000000000001711320473323400221070ustar00rootroot00000000000000module.exports = [ {a: 'a', m: {x: 'x'}}, {b: 'b', m: {x: 'q'}}, '', {d: 'd', m: {z: 'z'}}, null, {d: 'e'} ];extend-shallow-3.0.1/benchmark/index.js000066400000000000000000000006511320473323400200530ustar00rootroot00000000000000'use strict'; const path = require('path'); const argv = require('minimist')(process.argv.slice(2)); const suite = require('benchmarked'); const glob = argv._[0] || '*'; suite.run({code: `code/${glob}.js`, fixtures: `fixtures/*.js`}) .then(function(stats) { stats.forEach(function(target) { target.fastest = target.fastest || ['n/a']; }); console.log(suite.render(stats)); }) .catch(console.error); extend-shallow-3.0.1/bower.json000066400000000000000000000025601320473323400164660ustar00rootroot00000000000000{ "name": "extend-shallow", "description": "Extend an object with the properties of additional objects. node.js/javascript util.", "repository": "jonschlinkert/extend-shallow", "license": "MIT", "homepage": "https://github.com/jonschlinkert/extend-shallow", "authors": [ "Jon Schlinkert (https://github.com/jonschlinkert)" ], "main": [ "index.js" ], "dependencies": { "is-extendable": "^1.0.1" }, "devDependencies": { "array-slice": "^1.0.0", "benchmarked": "^2.0.0", "for-own": "^1.0.0", "gulp-format-md": "^1.0.0", "is-plain-object": "^2.0.4", "kind-of": "^6.0.1", "minimist": "^1.2.0", "mocha": "^3.5.3", "object-assign": "^4.1.1" }, "keywords": [ "assign", "clone", "extend", "merge", "obj", "object", "object-assign", "object.assign", "prop", "properties", "property", "props", "shallow", "util", "utility", "utils", "value" ], "version": "2.0.1", "bugs": { "url": "https://github.com/jonschlinkert/extend-shallow/issues" }, "files": [ "index.js" ], "ignore": [ "actual", "bower_components", "fixtures", "node_modules", "temp", "test", "test.js", "tmp" ], "contributors": [ "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Peter deHaan (http://about.me/peterdehaan)" ] }extend-shallow-3.0.1/index.js000066400000000000000000000013441320473323400161210ustar00rootroot00000000000000'use strict'; var isExtendable = require('is-extendable'); module.exports = Object.assign || function(obj/*, objects*/) { if (obj === null || typeof obj === 'undefined') { throw new TypeError('expected an object'); } for (var i = 1; i < arguments.length; i++) { var val = arguments[i]; if (isObject(val)) { assign(obj, val); } } return obj; }; function assign(a, b) { for (var key in b) { if (hasOwn(b, key)) { a[key] = b[key]; } } } function isObject(val) { return (val && typeof val === 'object') || isExtendable(val); } /** * Returns true if the given `key` is an own property of `obj`. */ function hasOwn(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } extend-shallow-3.0.1/package.json000066400000000000000000000032141320473323400167400ustar00rootroot00000000000000{ "name": "extend-shallow", "description": "Extend an object with the properties of additional objects. node.js/javascript util.", "version": "3.0.1", "homepage": "https://github.com/jonschlinkert/extend-shallow", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "contributors": [ "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Peter deHaan (http://about.me/peterdehaan)" ], "repository": "jonschlinkert/extend-shallow", "bugs": { "url": "https://github.com/jonschlinkert/extend-shallow/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, "dependencies": { "is-extendable": "^1.0.1" }, "devDependencies": { "array-slice": "^1.0.0", "benchmarked": "^2.0.0", "for-own": "^1.0.0", "gulp-format-md": "^1.0.0", "is-plain-object": "^2.0.4", "kind-of": "^6.0.1", "minimist": "^1.2.0", "mocha": "^3.5.3", "object-assign": "^4.1.1" }, "keywords": [ "assign", "clone", "extend", "merge", "obj", "object", "object-assign", "object.assign", "prop", "properties", "property", "props", "shallow", "util", "utility", "utils", "value" ], "verb": { "toc": false, "layout": "default", "tasks": [ "readme" ], "related": { "list": [ "extend-shallow", "for-in", "for-own", "is-plain-object", "isobject", "kind-of" ] }, "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true } } } extend-shallow-3.0.1/test.js000066400000000000000000000054001320473323400157660ustar00rootroot00000000000000/*! * extend-shallow * * Copyright (c) 2014-2015, Jon Schlinkert. * Licensed under the MIT License. */ 'use strict'; require('mocha'); const hasSymbol = typeof global.Symbol === 'function'; const path = require('path'); const argv = require('minimist')(process.argv.slice(2)); const assert = require('assert'); const extend = require('./'); if (argv && argv.lib) { extend = require(path.resolve('benchmark/code', argv.lib)); } describe('extend', function() { it('should extend the first object with the properties of the other objects', function() { assert.deepEqual(extend({a: 'b'}, {c: 'd'}), {a: 'b', c: 'd'}); assert.deepEqual(extend({a: 'b', c: 'd'}, {c: 'e'}), {a: 'b', c: 'e'}); }); it('should handle non-plain objects', function() { assert.deepEqual(extend({a: 'b'}, 'foo', {c: 'd'}), {0: 'f', 1: 'o', 2: 'o', a: 'b', c: 'd'}); assert.deepEqual(extend({a: 'b'}, null, {c: 'd'}), {a: 'b', c: 'd'}); assert.deepEqual(extend({a: 'b'}, new Date(), {c: 'd'}), {a: 'b', c: 'd'}); }); it('should extend a regex', function() { const fixture = /foo/; extend(fixture, {a: 'b'}, new Date(), {c: 'd'}); assert.equal(fixture.a, 'b'); assert.equal(fixture.c, 'd'); }); it('should extend a function', function() { const fixture = function() {}; extend(fixture, {a: 'b'}, new Date(), {c: 'd'}); assert.equal(fixture.a, 'b'); assert.equal(fixture.c, 'd'); }); it('should extend an array', function() { const arr = []; extend(arr, {a: 'b'}, new Date(), {c: 'd'}); assert.equal(arr.a, 'b'); assert.equal(arr.c, 'd'); }); it('should throw when the first arg is invalid', function() { assert.throws(function() { extend(null); }); assert.throws(function() { extend(undefined); }); assert.throws(function() { extend(); }); }); it('should return an empty object when non-object is passed', function() { assert.deepEqual(extend(123), {}); }); it('should not extend non-enumerable symbols', function() { if (!hasSymbol) return this.skip(); const fixture = {}; const obj = {}; const symbol = Symbol('foo'); Object.defineProperty(obj, symbol, {enumerable: false, value: 'bar'}); extend(fixture, obj); const other = extend({}, obj); assert.equal(typeof fixture[symbol], 'undefined'); assert.equal(typeof other[symbol], 'undefined'); }); it('should extend symbol properties', function() { if (!hasSymbol) return this.skip(); const fixture = {}; const obj = {}; const symbol = Symbol('foo'); obj[symbol] = 'bar'; extend(fixture, obj); const other = extend({}, obj); assert.equal(fixture[symbol], 'bar'); assert.equal(other[symbol], 'bar'); }); });