merge-anything 3.0.6 → 4.0.2
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/README.md +4 -2
- package/dist/index.cjs.js +7 -11
- package/dist/index.esm.js +7 -11
- package/package.json +43 -16
- package/src/extensions.ts +1 -0
- package/src/merge.ts +3 -6
- package/tsconfig.json +6 -2
- package/.eslintrc.js +0 -19
package/README.md
CHANGED
|
@@ -35,7 +35,9 @@ merge-anything will merge objects and nested properties, but only as long as the
|
|
|
35
35
|
|
|
36
36
|
## Usage
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
- Unlimited — Merge will merge an unlimited amount of plain objects you pass as the arguments
|
|
39
|
+
- Nested — Nested objects are merged deeply (see example below)
|
|
40
|
+
- No modification — Merge always returns a new object without modifying the original, but does keep object/array references for nested props (see [#A note on JavaScript object references](#a-note-on-javascript-object-references))
|
|
39
41
|
|
|
40
42
|
```js
|
|
41
43
|
import { merge } from 'merge-anything'
|
|
@@ -92,7 +94,7 @@ merge({ prop: 'a' }, { prop: {} }) // returns {prop: {}}
|
|
|
92
94
|
|
|
93
95
|
merge-anything properly keeps special objects intact like dates, regex, functions, class instances etc.
|
|
94
96
|
|
|
95
|
-
However, it's **very important** you understand how to work around JavaScript object references. Please be sure to read [a note on JavaScript object references](#a-note-on-javascript-object-references) down below.
|
|
97
|
+
However, it's **very important** you understand how to work around JavaScript object references. Please be sure to read [#a note on JavaScript object references](#a-note-on-javascript-object-references) down below.
|
|
96
98
|
|
|
97
99
|
## Concat arrays
|
|
98
100
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -19,14 +19,13 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
19
19
|
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
21
|
|
|
22
|
-
function
|
|
23
|
-
for (var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
r[k] = a[j];
|
|
27
|
-
return r;
|
|
22
|
+
function __spreadArray(to, from) {
|
|
23
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
24
|
+
to[j] = from[i];
|
|
25
|
+
return to;
|
|
28
26
|
}
|
|
29
27
|
|
|
28
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
30
29
|
function concatArrays(originVal, newVal) {
|
|
31
30
|
if (isWhat.isArray(originVal) && isWhat.isArray(newVal)) {
|
|
32
31
|
// concat logic
|
|
@@ -59,7 +58,7 @@ function mergeRecursively(origin, newComer, compareFn) {
|
|
|
59
58
|
if (isWhat.isPlainObject(origin)) {
|
|
60
59
|
var props_1 = Object.getOwnPropertyNames(origin);
|
|
61
60
|
var symbols_1 = Object.getOwnPropertySymbols(origin);
|
|
62
|
-
newObject =
|
|
61
|
+
newObject = __spreadArray(__spreadArray([], props_1), symbols_1).reduce(function (carry, key) {
|
|
63
62
|
var targetVal = origin[key];
|
|
64
63
|
if ((!isWhat.isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key)) ||
|
|
65
64
|
(isWhat.isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key))) {
|
|
@@ -71,7 +70,7 @@ function mergeRecursively(origin, newComer, compareFn) {
|
|
|
71
70
|
// newObject has all properties that newComer hasn't
|
|
72
71
|
var props = Object.getOwnPropertyNames(newComer);
|
|
73
72
|
var symbols = Object.getOwnPropertySymbols(newComer);
|
|
74
|
-
var result =
|
|
73
|
+
var result = __spreadArray(__spreadArray([], props), symbols).reduce(function (carry, key) {
|
|
75
74
|
// re-define the origin and newComer as targetVal and newVal
|
|
76
75
|
var newVal = newComer[key];
|
|
77
76
|
var targetVal = isWhat.isPlainObject(origin) ? origin[key] : undefined;
|
|
@@ -97,7 +96,6 @@ function merge(object) {
|
|
|
97
96
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
98
97
|
otherObjects[_i - 1] = arguments[_i];
|
|
99
98
|
}
|
|
100
|
-
// @ts-ignore
|
|
101
99
|
return otherObjects.reduce(function (result, newComer) {
|
|
102
100
|
return mergeRecursively(result, newComer);
|
|
103
101
|
}, object);
|
|
@@ -107,7 +105,6 @@ function mergeAndCompare(compareFn, object) {
|
|
|
107
105
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
108
106
|
otherObjects[_i - 2] = arguments[_i];
|
|
109
107
|
}
|
|
110
|
-
// @ts-ignore
|
|
111
108
|
return otherObjects.reduce(function (result, newComer) {
|
|
112
109
|
return mergeRecursively(result, newComer, compareFn);
|
|
113
110
|
}, object);
|
|
@@ -117,7 +114,6 @@ function mergeAndConcat(object) {
|
|
|
117
114
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
118
115
|
otherObjects[_i - 1] = arguments[_i];
|
|
119
116
|
}
|
|
120
|
-
// @ts-ignore
|
|
121
117
|
return otherObjects.reduce(function (result, newComer) {
|
|
122
118
|
return mergeRecursively(result, newComer, concatArrays);
|
|
123
119
|
}, object);
|
package/dist/index.esm.js
CHANGED
|
@@ -15,14 +15,13 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
15
15
|
PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
***************************************************************************** */
|
|
17
17
|
|
|
18
|
-
function
|
|
19
|
-
for (var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
r[k] = a[j];
|
|
23
|
-
return r;
|
|
18
|
+
function __spreadArray(to, from) {
|
|
19
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
20
|
+
to[j] = from[i];
|
|
21
|
+
return to;
|
|
24
22
|
}
|
|
25
23
|
|
|
24
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
26
25
|
function concatArrays(originVal, newVal) {
|
|
27
26
|
if (isArray(originVal) && isArray(newVal)) {
|
|
28
27
|
// concat logic
|
|
@@ -55,7 +54,7 @@ function mergeRecursively(origin, newComer, compareFn) {
|
|
|
55
54
|
if (isPlainObject(origin)) {
|
|
56
55
|
var props_1 = Object.getOwnPropertyNames(origin);
|
|
57
56
|
var symbols_1 = Object.getOwnPropertySymbols(origin);
|
|
58
|
-
newObject =
|
|
57
|
+
newObject = __spreadArray(__spreadArray([], props_1), symbols_1).reduce(function (carry, key) {
|
|
59
58
|
var targetVal = origin[key];
|
|
60
59
|
if ((!isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key)) ||
|
|
61
60
|
(isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key))) {
|
|
@@ -67,7 +66,7 @@ function mergeRecursively(origin, newComer, compareFn) {
|
|
|
67
66
|
// newObject has all properties that newComer hasn't
|
|
68
67
|
var props = Object.getOwnPropertyNames(newComer);
|
|
69
68
|
var symbols = Object.getOwnPropertySymbols(newComer);
|
|
70
|
-
var result =
|
|
69
|
+
var result = __spreadArray(__spreadArray([], props), symbols).reduce(function (carry, key) {
|
|
71
70
|
// re-define the origin and newComer as targetVal and newVal
|
|
72
71
|
var newVal = newComer[key];
|
|
73
72
|
var targetVal = isPlainObject(origin) ? origin[key] : undefined;
|
|
@@ -93,7 +92,6 @@ function merge(object) {
|
|
|
93
92
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
94
93
|
otherObjects[_i - 1] = arguments[_i];
|
|
95
94
|
}
|
|
96
|
-
// @ts-ignore
|
|
97
95
|
return otherObjects.reduce(function (result, newComer) {
|
|
98
96
|
return mergeRecursively(result, newComer);
|
|
99
97
|
}, object);
|
|
@@ -103,7 +101,6 @@ function mergeAndCompare(compareFn, object) {
|
|
|
103
101
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
104
102
|
otherObjects[_i - 2] = arguments[_i];
|
|
105
103
|
}
|
|
106
|
-
// @ts-ignore
|
|
107
104
|
return otherObjects.reduce(function (result, newComer) {
|
|
108
105
|
return mergeRecursively(result, newComer, compareFn);
|
|
109
106
|
}, object);
|
|
@@ -113,7 +110,6 @@ function mergeAndConcat(object) {
|
|
|
113
110
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
114
111
|
otherObjects[_i - 1] = arguments[_i];
|
|
115
112
|
}
|
|
116
|
-
// @ts-ignore
|
|
117
113
|
return otherObjects.reduce(function (result, newComer) {
|
|
118
114
|
return mergeRecursively(result, newComer, concatArrays);
|
|
119
115
|
}, object);
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "merge-anything",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "Merge objects & other types recursively. A simple & small integration.",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
8
|
-
"
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
|
|
11
11
|
"test": "ava",
|
|
12
12
|
"rollup": "rollup -c build/rollup.js",
|
|
13
|
-
"build": "npm run lint && npm run test && npm run rollup"
|
|
13
|
+
"build": "npm run lint && npm run test && npm run rollup",
|
|
14
|
+
"release": "npm run build && np"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -45,21 +46,23 @@
|
|
|
45
46
|
},
|
|
46
47
|
"homepage": "https://github.com/mesqueeb/merge-anything#readme",
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"is-what": "^3.
|
|
49
|
-
"ts-toolbelt": "^
|
|
49
|
+
"is-what": "^3.14.1",
|
|
50
|
+
"ts-toolbelt": "^9.6.0"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
53
|
-
"@typescript-eslint/parser": "^
|
|
54
|
-
"ava": "^3.
|
|
55
|
-
"eslint": "^
|
|
56
|
-
"eslint-config-prettier": "^
|
|
57
|
-
"eslint-plugin-tree-shaking": "^1.
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.3.1",
|
|
54
|
+
"@typescript-eslint/parser": "^5.3.1",
|
|
55
|
+
"ava": "^3.15.0",
|
|
56
|
+
"eslint": "^8.2.0",
|
|
57
|
+
"eslint-config-prettier": "^8.3.0",
|
|
58
|
+
"eslint-plugin-tree-shaking": "^1.9.2",
|
|
59
|
+
"np": "^7.5.0",
|
|
60
|
+
"prettier": "^2.4.1",
|
|
61
|
+
"rollup": "^2.59.0",
|
|
62
|
+
"rollup-plugin-typescript2": "^0.30.0",
|
|
63
|
+
"ts-node": "^10.4.0",
|
|
64
|
+
"tsconfig-paths": "^3.11.0",
|
|
65
|
+
"typescript": "^4.4.4"
|
|
63
66
|
},
|
|
64
67
|
"ava": {
|
|
65
68
|
"extensions": [
|
|
@@ -69,5 +72,29 @@
|
|
|
69
72
|
"tsconfig-paths/register",
|
|
70
73
|
"ts-node/register"
|
|
71
74
|
]
|
|
75
|
+
},
|
|
76
|
+
"np": {
|
|
77
|
+
"yarn": false,
|
|
78
|
+
"branch": "production"
|
|
79
|
+
},
|
|
80
|
+
"eslintConfig": {
|
|
81
|
+
"root": true,
|
|
82
|
+
"parser": "@typescript-eslint/parser",
|
|
83
|
+
"plugins": [
|
|
84
|
+
"@typescript-eslint",
|
|
85
|
+
"tree-shaking"
|
|
86
|
+
],
|
|
87
|
+
"extends": [
|
|
88
|
+
"eslint:recommended",
|
|
89
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
90
|
+
"plugin:@typescript-eslint/recommended",
|
|
91
|
+
"prettier"
|
|
92
|
+
],
|
|
93
|
+
"rules": {
|
|
94
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
95
|
+
"@typescript-eslint/ban-ts-ignore": "off",
|
|
96
|
+
"tree-shaking/no-side-effects-in-initialization": "error",
|
|
97
|
+
"@typescript-eslint/ban-ts-comment": "off"
|
|
98
|
+
}
|
|
72
99
|
}
|
|
73
100
|
}
|
package/src/extensions.ts
CHANGED
package/src/merge.ts
CHANGED
|
@@ -77,10 +77,9 @@ export function merge<T extends Record<string, any>, Tn extends Record<string, a
|
|
|
77
77
|
object: T,
|
|
78
78
|
...otherObjects: Tn
|
|
79
79
|
): O.Assign<T, Tn, 'deep'> {
|
|
80
|
-
// @ts-ignore
|
|
81
80
|
return otherObjects.reduce((result, newComer) => {
|
|
82
81
|
return mergeRecursively(result, newComer)
|
|
83
|
-
}, object)
|
|
82
|
+
}, object) as any
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
export function mergeAndCompare<T extends Record<string, any>, Tn extends Record<string, any>[]>(
|
|
@@ -88,18 +87,16 @@ export function mergeAndCompare<T extends Record<string, any>, Tn extends Record
|
|
|
88
87
|
object: T,
|
|
89
88
|
...otherObjects: Tn
|
|
90
89
|
): O.Assign<T, Tn, 'deep'> {
|
|
91
|
-
// @ts-ignore
|
|
92
90
|
return otherObjects.reduce((result, newComer) => {
|
|
93
91
|
return mergeRecursively(result, newComer, compareFn)
|
|
94
|
-
}, object)
|
|
92
|
+
}, object) as any
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
export function mergeAndConcat<T extends Record<string, any>, Tn extends Record<string, any>[]>(
|
|
98
96
|
object: T,
|
|
99
97
|
...otherObjects: Tn
|
|
100
98
|
): O.Assign<T, Tn, 'deep'> {
|
|
101
|
-
// @ts-ignore
|
|
102
99
|
return otherObjects.reduce((result, newComer) => {
|
|
103
100
|
return mergeRecursively(result, newComer, concatArrays)
|
|
104
|
-
}, object)
|
|
101
|
+
}, object) as any
|
|
105
102
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"baseUrl": ".",
|
|
4
|
+
"lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020"],
|
|
5
|
+
"strict": true,
|
|
6
|
+
"isolatedModules": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"moduleResolution": "node",
|
|
4
9
|
"declaration": true,
|
|
5
|
-
"declarationDir": "./types/"
|
|
6
|
-
"strict": true
|
|
10
|
+
"declarationDir": "./types/"
|
|
7
11
|
},
|
|
8
12
|
"include": [
|
|
9
13
|
"src/**/*",
|
package/.eslintrc.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-plugin-tree-shaking
|
|
2
|
-
module.exports = {
|
|
3
|
-
root: true,
|
|
4
|
-
parser: '@typescript-eslint/parser',
|
|
5
|
-
plugins: ['@typescript-eslint', 'tree-shaking'],
|
|
6
|
-
extends: [
|
|
7
|
-
'eslint:recommended',
|
|
8
|
-
'plugin:@typescript-eslint/eslint-recommended',
|
|
9
|
-
'plugin:@typescript-eslint/recommended',
|
|
10
|
-
'prettier/@typescript-eslint'
|
|
11
|
-
],
|
|
12
|
-
rules: {
|
|
13
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
14
|
-
'@typescript-eslint/ban-ts-ignore': 'off',
|
|
15
|
-
'tree-shaking/no-side-effects-in-initialization': 'error',
|
|
16
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
17
|
-
'@typescript-eslint/ban-ts-comment': 'off'
|
|
18
|
-
}
|
|
19
|
-
}
|