mixin-deep 1.3.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +23 -11
- package/index.js +20 -31
- package/package.json +6 -10
package/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2014-
|
3
|
+
Copyright (c) 2014-present, Jon Schlinkert.
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# mixin-deep [](https://www.npmjs.com/package/mixin-deep) [](https://npmjs.org/package/mixin-deep) [](https://npmjs.org/package/mixin-deep) [](https://travis-ci.org/jonschlinkert/mixin-deep)
|
1
|
+
# mixin-deep [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [](https://www.npmjs.com/package/mixin-deep) [](https://npmjs.org/package/mixin-deep) [](https://npmjs.org/package/mixin-deep) [](https://travis-ci.org/jonschlinkert/mixin-deep)
|
2
2
|
|
3
|
-
> Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone.
|
3
|
+
> Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. No dependencies.
|
4
4
|
|
5
5
|
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
6
6
|
|
@@ -12,13 +12,17 @@ Install with [npm](https://www.npmjs.com/):
|
|
12
12
|
$ npm install --save mixin-deep
|
13
13
|
```
|
14
14
|
|
15
|
+
## Heads up!
|
16
|
+
|
17
|
+
[Please update](https://gist.github.com/jonschlinkert/9a62534c4f8bc76aee6058caa3f05fd6) to version 2.0.1 or later, a critical bug was fixed in that version.
|
18
|
+
|
15
19
|
## Usage
|
16
20
|
|
17
21
|
```js
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
//=> { a: {
|
22
|
+
const mixin = require('mixin-deep');
|
23
|
+
const res = mixin({ a: { foo: true } }, { a: { bar: true } }, { a: { baz: true } });
|
24
|
+
console.log(res);
|
25
|
+
//=> { a: { foo: true, bar: true, baz: true } }
|
22
26
|
```
|
23
27
|
|
24
28
|
## About
|
@@ -40,6 +44,7 @@ $ npm install && npm test
|
|
40
44
|
```
|
41
45
|
|
42
46
|
</details>
|
47
|
+
|
43
48
|
<details>
|
44
49
|
<summary><strong>Building docs</strong></summary>
|
45
50
|
|
@@ -62,19 +67,26 @@ You might also be interested in these projects:
|
|
62
67
|
* [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.")
|
63
68
|
* [mixin-object](https://www.npmjs.com/package/mixin-object): Mixin the own and inherited properties of other objects onto the first object. Pass an… [more](https://github.com/jonschlinkert/mixin-object) | [homepage](https://github.com/jonschlinkert/mixin-object "Mixin the own and inherited properties of other objects onto the first object. Pass an empty object as the first arg to shallow clone.")
|
64
69
|
|
70
|
+
### Contributors
|
71
|
+
|
72
|
+
| **Commits** | **Contributor** |
|
73
|
+
| --- | --- |
|
74
|
+
| 28 | [jonschlinkert](https://github.com/jonschlinkert) |
|
75
|
+
| 2 | [doowb](https://github.com/doowb) |
|
76
|
+
|
65
77
|
### Author
|
66
78
|
|
67
79
|
**Jon Schlinkert**
|
68
80
|
|
69
|
-
* [
|
70
|
-
* [
|
71
|
-
* [
|
81
|
+
* [GitHub Profile](https://github.com/jonschlinkert)
|
82
|
+
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
83
|
+
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
72
84
|
|
73
85
|
### License
|
74
86
|
|
75
|
-
Copyright ©
|
87
|
+
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
76
88
|
Released under the [MIT License](LICENSE).
|
77
89
|
|
78
90
|
***
|
79
91
|
|
80
|
-
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.
|
92
|
+
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on June 19, 2019._
|
package/index.js
CHANGED
@@ -1,49 +1,38 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
const isObject = val => {
|
4
|
+
return typeof val === 'function' || (typeof val === 'object' && val !== null && !Array.isArray(val));
|
5
|
+
};
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
const isValidKey = key => {
|
8
|
+
return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
|
9
|
+
};
|
10
|
+
|
11
|
+
const mixinDeep = (target, ...rest) => {
|
12
|
+
for (let obj of rest) {
|
10
13
|
if (isObject(obj)) {
|
11
|
-
|
14
|
+
for (let key in obj) {
|
15
|
+
if (isValidKey(key)) {
|
16
|
+
mixin(target, obj[key], key);
|
17
|
+
}
|
18
|
+
}
|
12
19
|
}
|
13
20
|
}
|
14
21
|
return target;
|
15
|
-
}
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Copy properties from the source object to the
|
19
|
-
* target object.
|
20
|
-
*
|
21
|
-
* @param {*} `val`
|
22
|
-
* @param {String} `key`
|
23
|
-
*/
|
22
|
+
};
|
24
23
|
|
25
|
-
function
|
26
|
-
|
24
|
+
function mixin(target, val, key) {
|
25
|
+
let obj = target[key];
|
27
26
|
if (isObject(val) && isObject(obj)) {
|
28
27
|
mixinDeep(obj, val);
|
29
28
|
} else {
|
30
|
-
|
29
|
+
target[key] = val;
|
31
30
|
}
|
32
31
|
}
|
33
32
|
|
34
33
|
/**
|
35
|
-
*
|
36
|
-
*
|
37
|
-
* @param {any} val
|
38
|
-
* @return {Boolean}
|
39
|
-
*/
|
40
|
-
|
41
|
-
function isObject(val) {
|
42
|
-
return isExtendable(val) && !Array.isArray(val);
|
43
|
-
}
|
44
|
-
|
45
|
-
/**
|
46
|
-
* Expose `mixinDeep`
|
34
|
+
* Expose mixinDeep
|
35
|
+
* @type {Function}
|
47
36
|
*/
|
48
37
|
|
49
38
|
module.exports = mixinDeep;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "mixin-deep",
|
3
|
-
"description": "Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone.",
|
4
|
-
"version": "
|
3
|
+
"description": "Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. No dependencies.",
|
4
|
+
"version": "2.0.1",
|
5
5
|
"homepage": "https://github.com/jonschlinkert/mixin-deep",
|
6
6
|
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
7
7
|
"repository": "jonschlinkert/mixin-deep",
|
@@ -14,21 +14,17 @@
|
|
14
14
|
],
|
15
15
|
"main": "index.js",
|
16
16
|
"engines": {
|
17
|
-
"node": ">=
|
17
|
+
"node": ">=6"
|
18
18
|
},
|
19
19
|
"scripts": {
|
20
20
|
"test": "mocha"
|
21
21
|
},
|
22
|
-
"dependencies": {
|
23
|
-
"for-in": "^1.0.2",
|
24
|
-
"is-extendable": "^1.0.1"
|
25
|
-
},
|
26
22
|
"devDependencies": {
|
27
|
-
"gulp-format-md": "^
|
28
|
-
"mocha": "^
|
29
|
-
"should": "^13.1.3"
|
23
|
+
"gulp-format-md": "^2.0.0",
|
24
|
+
"mocha": "^6.1.4"
|
30
25
|
},
|
31
26
|
"keywords": [
|
27
|
+
"assign",
|
32
28
|
"deep",
|
33
29
|
"extend",
|
34
30
|
"key",
|