├── .gitattributes ├── .travis.yml ├── .editorconfig ├── .gitignore ├── .verb.md ├── index.js ├── LICENSE ├── bower.json ├── package.json ├── test.js ├── .eslintrc.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - iojs 9 | - '8' 10 | - '7' 11 | - '6' 12 | - '5' 13 | - '4' 14 | - '0.12' 15 | - '0.10' 16 | git: 17 | depth: 10 18 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | .idea 4 | *.sublime-* 5 | 6 | # test related, or directories generated by tests 7 | test/actual 8 | actual 9 | coverage 10 | .nyc* 11 | 12 | # npm 13 | node_modules 14 | npm-debug.log 15 | 16 | # yarn 17 | yarn.lock 18 | yarn-error.log 19 | 20 | # misc 21 | _gh_pages 22 | _draft 23 | _drafts 24 | bower_components 25 | vendor 26 | temp 27 | tmp 28 | TODO.md 29 | package-lock.json -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | If you only want to combine own-properties, use [extend-shallow](https://github.com/jonschlinkert/extend-shallow). 2 | 3 | ## Usage 4 | 5 | ```js 6 | var mixin = require('{%= name %}'); 7 | 8 | var obj = {c: 'c'}; 9 | var foo = mixin({a: 'a'}, {b: 'b'}); 10 | console.log(foo); 11 | //=> {c: 'c', a: 'a', b: 'b'} 12 | console.log(obj); 13 | //=> {c: 'c'} 14 | 15 | mixin({}, {a: 'a'}, {b: 'b'}); 16 | //=> {a: 'a', b: 'b'} 17 | ``` 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var isObject = require('is-extendable'); 4 | var forIn = require('for-in'); 5 | 6 | module.exports = function mixin(target, objects) { 7 | if (!isObject(target)) { 8 | throw new TypeError('expected the first argument to be an object'); 9 | } 10 | 11 | var len = arguments.length; 12 | var idx = 0; 13 | 14 | while (++idx < len) { 15 | copy(target, arguments[idx]); 16 | } 17 | return target; 18 | }; 19 | 20 | /** 21 | * copy properties from the source object to the 22 | * target object. We don't use `Object.keys` here, since 23 | * "mixin" also adds non-enumerable keys. 24 | * 25 | * @param {*} `value` 26 | * @param {String} `key` 27 | */ 28 | 29 | function copy(target, obj) { 30 | if (isObject(obj)) { 31 | forIn(obj, function(value, key) { 32 | target[key] = value; 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2017, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mixin-object", 3 | "description": "Mixin the own and inherited properties of other objects onto the first object. Pass an empty object as the first arg to shallow clone.", 4 | "repository": "jonschlinkert/mixin-object", 5 | "license": "MIT", 6 | "homepage": "https://github.com/jonschlinkert/mixin-object", 7 | "authors": [ 8 | "Jon Schlinkert (https://github.com/jonschlinkert)" 9 | ], 10 | "main": [ 11 | "index.js" 12 | ], 13 | "dependencies": { 14 | "for-in": "^1.0.2", 15 | "is-extendable": "^1.0.0" 16 | }, 17 | "devDependencies": { 18 | "gulp-format-md": "^1.0.0", 19 | "mocha": "^3.5.0" 20 | }, 21 | "keywords": [ 22 | "assign", 23 | "copy", 24 | "extend", 25 | "key", 26 | "merge", 27 | "mixin", 28 | "object", 29 | "objects", 30 | "prop", 31 | "properties", 32 | "property", 33 | "shallow", 34 | "util", 35 | "value" 36 | ], 37 | "version": "2.0.1", 38 | "bugs": { 39 | "url": "https://github.com/jonschlinkert/mixin-object/issues" 40 | }, 41 | "files": [ 42 | "index.js" 43 | ], 44 | "ignore": [ 45 | "actual", 46 | "bower_components", 47 | "fixtures", 48 | "node_modules", 49 | "temp", 50 | "test", 51 | "test.js", 52 | "tmp" 53 | ] 54 | } 55 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mixin-object", 3 | "description": "Mixin the own and inherited properties of other objects onto the first object. Pass an empty object as the first arg to shallow clone.", 4 | "version": "3.0.0", 5 | "homepage": "https://github.com/jonschlinkert/mixin-object", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/mixin-object", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/mixin-object/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js" 14 | ], 15 | "main": "index.js", 16 | "engines": { 17 | "node": ">=0.10.0" 18 | }, 19 | "scripts": { 20 | "test": "mocha" 21 | }, 22 | "dependencies": { 23 | "for-in": "^1.0.2", 24 | "is-extendable": "^1.0.0" 25 | }, 26 | "devDependencies": { 27 | "gulp-format-md": "^1.0.0", 28 | "mocha": "^3.5.0" 29 | }, 30 | "keywords": [ 31 | "assign", 32 | "copy", 33 | "extend", 34 | "key", 35 | "merge", 36 | "mixin", 37 | "object", 38 | "objects", 39 | "prop", 40 | "properties", 41 | "property", 42 | "shallow", 43 | "util", 44 | "value" 45 | ], 46 | "verb": { 47 | "toc": false, 48 | "layout": "default", 49 | "tasks": [ 50 | "readme" 51 | ], 52 | "related": { 53 | "list": [ 54 | "assign-deep", 55 | "defaults-deep", 56 | "extend-shallow", 57 | "for-in", 58 | "for-own", 59 | "is-plain-object", 60 | "isobject", 61 | "merge-deep", 62 | "mixin-deep" 63 | ] 64 | }, 65 | "plugins": [ 66 | "gulp-format-md" 67 | ], 68 | "lint": { 69 | "reflinks": true 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var assert = require('assert'); 5 | var mixin = require('./'); 6 | 7 | describe('mixin-object', function() { 8 | it('should throw an error when the first argument is not an object.', function() { 9 | assert.throws(function() { 10 | mixin(); 11 | }); 12 | }); 13 | 14 | it('should mix all objects into the first one.', function() { 15 | var obj = {c: 'c'}; 16 | mixin(obj, {a: 'a'}, {b: 'b'}); 17 | assert.deepEqual(obj, {c: 'c', a: 'a', b: 'b'}); 18 | }); 19 | 20 | it('should return a new object when an empty object is passed.', function() { 21 | var c = {c: 'c'}; 22 | var d = mixin({}, c, {a: 'a'}, {b: 'b'}); 23 | assert.deepEqual(c, {c: 'c'}); 24 | assert.deepEqual(d, {c: 'c', a: 'a', b: 'b'}); 25 | }); 26 | 27 | it('should mix properties onto a function.', function() { 28 | function foo() {} 29 | var c = {c: 'c'}; 30 | var d = mixin(foo, c, {a: 'a'}, {b: 'b'}); 31 | assert(foo.hasOwnProperty('a')); 32 | assert(foo.hasOwnProperty('b')); 33 | assert(foo.hasOwnProperty('c')); 34 | }); 35 | 36 | it('should mixin all objects.', function() { 37 | assert.deepEqual(mixin({a: 'a'}, {b: 'b'}), {a: 'a', b: 'b'}); 38 | assert.deepEqual(mixin({a: 'a'}, {b: 'b'}, {c: 'c'}), {a: 'a', b: 'b', c: 'c'}); 39 | assert.deepEqual(mixin({a: 'a'}, {b: {c: 'c'}}, {d: 'd'}), {a: 'a', b: {c: 'c'}, d: 'd'}); 40 | }); 41 | 42 | it('should create a new object.', function() { 43 | assert.deepEqual(mixin({}, {a: 'a'}, {b: 'b'}), {a: 'a', b: 'b'}); 44 | assert.deepEqual(mixin({}, {a: 'a'}, {b: 'b'}, {c: 'c'}), {a: 'a', b: 'b', c: 'c'}); 45 | assert.deepEqual(mixin({}, {a: 'a'}, {b: {c: 'c'}}, {d: 'd'}), {a: 'a', b: {c: 'c'}, d: 'd'}); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": false, 4 | "es6": true, 5 | "node": true, 6 | "mocha": true 7 | }, 8 | 9 | "globals": { 10 | "document": false, 11 | "navigator": false, 12 | "window": false 13 | }, 14 | 15 | "rules": { 16 | "accessor-pairs": 2, 17 | "arrow-spacing": [2, { "before": true, "after": true }], 18 | "block-spacing": [2, "always"], 19 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 20 | "comma-dangle": [2, "never"], 21 | "comma-spacing": [2, { "before": false, "after": true }], 22 | "comma-style": [2, "last"], 23 | "constructor-super": 2, 24 | "curly": [2, "multi-line"], 25 | "dot-location": [2, "property"], 26 | "eol-last": 2, 27 | "eqeqeq": [2, "allow-null"], 28 | "generator-star-spacing": [2, { "before": true, "after": true }], 29 | "handle-callback-err": [2, "^(err|error)$" ], 30 | "indent": [2, 2, { "SwitchCase": 1 }], 31 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 32 | "keyword-spacing": [2, { "before": true, "after": true }], 33 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 34 | "new-parens": 2, 35 | "no-array-constructor": 2, 36 | "no-caller": 2, 37 | "no-class-assign": 2, 38 | "no-cond-assign": 2, 39 | "no-const-assign": 2, 40 | "no-control-regex": 2, 41 | "no-debugger": 2, 42 | "no-delete-var": 2, 43 | "no-dupe-args": 2, 44 | "no-dupe-class-members": 2, 45 | "no-dupe-keys": 2, 46 | "no-duplicate-case": 2, 47 | "no-empty-character-class": 2, 48 | "no-eval": 2, 49 | "no-ex-assign": 2, 50 | "no-extend-native": 2, 51 | "no-extra-bind": 2, 52 | "no-extra-boolean-cast": 2, 53 | "no-extra-parens": [2, "functions"], 54 | "no-fallthrough": 2, 55 | "no-floating-decimal": 2, 56 | "no-func-assign": 2, 57 | "no-implied-eval": 2, 58 | "no-inner-declarations": [2, "functions"], 59 | "no-invalid-regexp": 2, 60 | "no-irregular-whitespace": 2, 61 | "no-iterator": 2, 62 | "no-label-var": 2, 63 | "no-labels": 2, 64 | "no-lone-blocks": 2, 65 | "no-mixed-spaces-and-tabs": 2, 66 | "no-multi-spaces": 2, 67 | "no-multi-str": 2, 68 | "no-multiple-empty-lines": [2, { "max": 1 }], 69 | "no-native-reassign": 0, 70 | "no-negated-in-lhs": 2, 71 | "no-new": 2, 72 | "no-new-func": 2, 73 | "no-new-object": 2, 74 | "no-new-require": 2, 75 | "no-new-wrappers": 2, 76 | "no-obj-calls": 2, 77 | "no-octal": 2, 78 | "no-octal-escape": 2, 79 | "no-proto": 0, 80 | "no-redeclare": 2, 81 | "no-regex-spaces": 2, 82 | "no-return-assign": 2, 83 | "no-self-compare": 2, 84 | "no-sequences": 2, 85 | "no-shadow-restricted-names": 2, 86 | "no-spaced-func": 2, 87 | "no-sparse-arrays": 2, 88 | "no-this-before-super": 2, 89 | "no-throw-literal": 2, 90 | "no-trailing-spaces": 0, 91 | "no-undef": 2, 92 | "no-undef-init": 2, 93 | "no-unexpected-multiline": 2, 94 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 95 | "no-unreachable": 2, 96 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 97 | "no-useless-call": 0, 98 | "no-with": 2, 99 | "one-var": [0, { "initialized": "never" }], 100 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 101 | "padded-blocks": [0, "never"], 102 | "quotes": [2, "single", "avoid-escape"], 103 | "radix": 2, 104 | "semi": [2, "always"], 105 | "semi-spacing": [2, { "before": false, "after": true }], 106 | "space-before-blocks": [2, "always"], 107 | "space-before-function-paren": [2, "never"], 108 | "space-in-parens": [2, "never"], 109 | "space-infix-ops": 2, 110 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 111 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 112 | "use-isnan": 2, 113 | "valid-typeof": 2, 114 | "wrap-iife": [2, "any"], 115 | "yoda": [2, "never"] 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mixin-object [![NPM version](https://img.shields.io/npm/v/mixin-object.svg?style=flat)](https://www.npmjs.com/package/mixin-object) [![NPM monthly downloads](https://img.shields.io/npm/dm/mixin-object.svg?style=flat)](https://npmjs.org/package/mixin-object) [![NPM total downloads](https://img.shields.io/npm/dt/mixin-object.svg?style=flat)](https://npmjs.org/package/mixin-object) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/mixin-object.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/mixin-object) 2 | 3 | > Mixin the own and inherited properties of other objects onto the first object. Pass an empty object as the first arg to shallow clone. 4 | 5 | Follow this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), for updates on this project and others. 6 | 7 | ## Install 8 | 9 | Install with [npm](https://www.npmjs.com/): 10 | 11 | ```sh 12 | $ npm install --save mixin-object 13 | ``` 14 | 15 | If you only want to combine own-properties, use [extend-shallow](https://github.com/jonschlinkert/extend-shallow). 16 | 17 | ## Usage 18 | 19 | ```js 20 | var mixin = require('mixin-object'); 21 | 22 | var obj = {c: 'c'}; 23 | var foo = mixin({a: 'a'}, {b: 'b'}); 24 | console.log(foo); 25 | //=> {c: 'c', a: 'a', b: 'b'} 26 | console.log(obj); 27 | //=> {c: 'c'} 28 | 29 | mixin({}, {a: 'a'}, {b: 'b'}); 30 | //=> {a: 'a', b: 'b'} 31 | ``` 32 | 33 | ## About 34 | 35 | ### Related projects 36 | 37 | You might also be interested in these projects: 38 | 39 | * [assign-deep](https://www.npmjs.com/package/assign-deep): Deeply assign the enumerable properties and/or es6 Symbol properies of source objects to the target… [more](https://github.com/jonschlinkert/assign-deep) | [homepage](https://github.com/jonschlinkert/assign-deep "Deeply assign the enumerable properties and/or es6 Symbol properies of source objects to the target (first) object.") 40 | * [defaults-deep](https://www.npmjs.com/package/defaults-deep): Like `extend` but recursively copies only the missing properties/values to the target object. | [homepage](https://github.com/jonschlinkert/defaults-deep "Like `extend` but recursively copies only the missing properties/values to the target object.") 41 | * [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.") 42 | * [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") 43 | * [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.") 44 | * [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.") 45 | * [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.") 46 | * [merge-deep](https://www.npmjs.com/package/merge-deep): Recursively merge values in a javascript object. | [homepage](https://github.com/jonschlinkert/merge-deep "Recursively merge values in a javascript object.") 47 | * [mixin-deep](https://www.npmjs.com/package/mixin-deep): Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | [homepage](https://github.com/jonschlinkert/mixin-deep "Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone.") 48 | 49 | ### Contributing 50 | 51 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 52 | 53 | ### Building docs 54 | 55 | _(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.)_ 56 | 57 | To generate the readme, run the following command: 58 | 59 | ```sh 60 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 61 | ``` 62 | 63 | ### Running tests 64 | 65 | 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: 66 | 67 | ```sh 68 | $ npm install && npm test 69 | ``` 70 | 71 | ### Author 72 | 73 | **Jon Schlinkert** 74 | 75 | * [github/jonschlinkert](https://github.com/jonschlinkert) 76 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) 77 | 78 | ### License 79 | 80 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 81 | Released under the [MIT License](LICENSE). 82 | 83 | *** 84 | 85 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 04, 2017._ --------------------------------------------------------------------------------