mixin-deep
Advanced tools
Comparing version 1.3.1 to 2.0.0
45
index.js
'use strict'; | ||
var isExtendable = require('is-extendable'); | ||
var forIn = require('for-in'); | ||
function mixinDeep(target, objects) { | ||
var len = arguments.length, i = 0; | ||
while (++i < len) { | ||
var obj = arguments[i]; | ||
function mixinDeep(target, ...rest) { | ||
for (let obj of rest) { | ||
if (isObject(obj)) { | ||
forIn(obj, copy, target); | ||
for (let key in obj) { | ||
if (key !== '__proto__') { | ||
mixin(target, obj[key], key); | ||
} | ||
} | ||
} | ||
@@ -17,38 +16,20 @@ } | ||
/** | ||
* Copy properties from the source object to the | ||
* target object. | ||
* | ||
* @param {*} `val` | ||
* @param {String} `key` | ||
*/ | ||
function copy(val, key) { | ||
if (key === '__proto__') { | ||
return; | ||
} | ||
var obj = this[key]; | ||
function mixin(target, val, key) { | ||
let obj = target[key]; | ||
if (isObject(val) && isObject(obj)) { | ||
mixinDeep(obj, val); | ||
} else { | ||
this[key] = val; | ||
target[key] = val; | ||
} | ||
} | ||
/** | ||
* Returns true if `val` is an object or function. | ||
* | ||
* @param {any} val | ||
* @return {Boolean} | ||
*/ | ||
function isObject(val) { | ||
return isExtendable(val) && !Array.isArray(val); | ||
return typeof val === 'function' || (typeof val === 'object' && val !== null && !Array.isArray(val)); | ||
} | ||
/** | ||
* Expose `mixinDeep` | ||
* Expose mixinDeep | ||
* @type {Function} | ||
*/ | ||
module.exports = mixinDeep; |
{ | ||
"name": "mixin-deep", | ||
"description": "Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone.", | ||
"version": "1.3.1", | ||
"description": "Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. No dependencies.", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jonschlinkert/mixin-deep", | ||
@@ -17,3 +17,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
@@ -23,10 +23,5 @@ "scripts": { | ||
}, | ||
"dependencies": { | ||
"for-in": "^1.0.2", | ||
"is-extendable": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"gulp-format-md": "^1.0.0", | ||
"mocha": "^3.5.3", | ||
"should": "^13.1.3" | ||
"mocha": "^5.2.0" | ||
}, | ||
@@ -33,0 +28,0 @@ "keywords": [ |
# mixin-deep [![NPM version](https://img.shields.io/npm/v/mixin-deep.svg?style=flat)](https://www.npmjs.com/package/mixin-deep) [![NPM monthly downloads](https://img.shields.io/npm/dm/mixin-deep.svg?style=flat)](https://npmjs.org/package/mixin-deep) [![NPM total downloads](https://img.shields.io/npm/dt/mixin-deep.svg?style=flat)](https://npmjs.org/package/mixin-deep) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/mixin-deep.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/mixin-deep) | ||
> Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | ||
> Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. No dependencies. | ||
@@ -18,6 +18,6 @@ Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. | ||
```js | ||
var mixinDeep = require('mixin-deep'); | ||
mixinDeep({a: {aa: 'aa'}}, {a: {bb: 'bb'}}, {a: {cc: 'cc'}}); | ||
//=> { a: { aa: 'aa', bb: 'bb', cc: 'cc' } } | ||
const mixin = require('mixin-deep'); | ||
const res = mixin({ a: { foo: true } }, { a: { bar: true } }, { a: { baz: true } }); | ||
console.log(res); | ||
//=> { a: { foo: true, bar: true, baz: true } } | ||
``` | ||
@@ -44,2 +44,3 @@ | ||
</details> | ||
<details> | ||
@@ -67,2 +68,9 @@ <summary><strong>Building docs</strong></summary> | ||
### Contributors | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 26 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 2 | [doowb](https://github.com/doowb) | | ||
### Author | ||
@@ -72,9 +80,9 @@ | ||
* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
### License | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
@@ -84,2 +92,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on December 09, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 11, 2018._ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
2
88
0
6849
29
- Removedfor-in@^1.0.2
- Removedis-extendable@^1.0.1
- Removedfor-in@1.0.2(transitive)
- Removedis-extendable@1.0.1(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedisobject@3.0.1(transitive)