merge-anything 3.0.7 → 4.0.3
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 +24 -16
- package/dist/index.cjs +92 -0
- package/dist/index.es.js +85 -0
- package/{types → dist/types}/extensions.d.ts +0 -0
- package/{types → dist/types}/index.d.ts +0 -0
- package/dist/types/merge.d.ts +11 -0
- package/package.json +67 -26
- package/.eslintignore +0 -8
- package/.eslintrc.js +0 -17
- package/.github/FUNDING.yml +0 -12
- package/.github/typescript-support.png +0 -0
- package/.prettierrc +0 -9
- package/_playground.ts +0 -27
- package/build/rollup.js +0 -55
- package/dist/index.cjs.js +0 -134
- package/dist/index.esm.js +0 -127
- package/src/extensions.ts +0 -9
- package/src/index.ts +0 -2
- package/src/merge.ts +0 -110
- package/test/index.ts +0 -320
- package/test/mergeAndCompare.ts +0 -64
- package/test/mergeAndConcat.ts +0 -15
- package/tsconfig.json +0 -10
- package/types/merge.d.ts +0 -16
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Merge anything 🥡
|
|
2
2
|
|
|
3
|
+
<a href="https://www.npmjs.com/package/merge-anything"><img src="https://img.shields.io/npm/v/merge-anything.svg" alt="Total Downloads"></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/merge-anything"><img src="https://img.shields.io/npm/dw/merge-anything.svg" alt="Latest Stable Version"></a>
|
|
5
|
+
|
|
3
6
|
```
|
|
4
7
|
npm i merge-anything
|
|
5
8
|
```
|
|
@@ -35,7 +38,9 @@ merge-anything will merge objects and nested properties, but only as long as the
|
|
|
35
38
|
|
|
36
39
|
## Usage
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
- Unlimited — Merge will merge an unlimited amount of plain objects you pass as the arguments
|
|
42
|
+
- Nested — Nested objects are merged deeply (see example below)
|
|
43
|
+
- 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
44
|
|
|
40
45
|
```js
|
|
41
46
|
import { merge } from 'merge-anything'
|
|
@@ -68,11 +73,13 @@ This package will recursively go through plain objects and merge the values onto
|
|
|
68
73
|
// all passed objects do not get modified
|
|
69
74
|
const a = { a: 'a' }
|
|
70
75
|
const b = { b: 'b' }
|
|
71
|
-
const c =
|
|
76
|
+
const c = { c: 'c' }
|
|
77
|
+
const result = merge(a, b, c)
|
|
72
78
|
// a === {a: 'a'}
|
|
73
79
|
// b === {b: 'b'}
|
|
74
|
-
// c === {
|
|
75
|
-
//
|
|
80
|
+
// c === {c: 'c'}
|
|
81
|
+
// result === {a: 'a', b: 'b', c: 'c'}
|
|
82
|
+
// However, be careful with JavaScript object references with nested props. See below: A note on JavaScript object references
|
|
76
83
|
|
|
77
84
|
// arrays get overwritten
|
|
78
85
|
// (for "concat" logic, see Extensions below)
|
|
@@ -83,7 +90,6 @@ merge({ obj: { prop: 'a' } }, { obj: {} }) // returns {obj: {prop: 'a'}}
|
|
|
83
90
|
|
|
84
91
|
// but non-objects overwrite objects
|
|
85
92
|
merge({ obj: { prop: 'a' } }, { obj: null }) // returns {obj: null}
|
|
86
|
-
merge({ obj: 'a' }, 'b') // returns 'b'
|
|
87
93
|
|
|
88
94
|
// and empty objects overwrite non-objects
|
|
89
95
|
merge({ prop: 'a' }, { prop: {} }) // returns {prop: {}}
|
|
@@ -91,7 +97,7 @@ merge({ prop: 'a' }, { prop: {} }) // returns {prop: {}}
|
|
|
91
97
|
|
|
92
98
|
merge-anything properly keeps special objects intact like dates, regex, functions, class instances etc.
|
|
93
99
|
|
|
94
|
-
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.
|
|
100
|
+
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.
|
|
95
101
|
|
|
96
102
|
## Concat arrays
|
|
97
103
|
|
|
@@ -113,9 +119,11 @@ mergeAndConcat(
|
|
|
113
119
|
|
|
114
120
|
There might be times you need to tweak the logic when two things are merged. You can provide your own custom function that's triggered every time a value is overwritten.
|
|
115
121
|
|
|
116
|
-
Here is an example with a compare function that concatenates strings:
|
|
122
|
+
For this case we use `mergeAndCompare`. Here is an example with a compare function that concatenates strings:
|
|
117
123
|
|
|
118
124
|
```js
|
|
125
|
+
import { mergeAndCompare } from 'merge-anything'
|
|
126
|
+
|
|
119
127
|
function concatStrings (originVal, newVal, key) {
|
|
120
128
|
if (typeof originVal === 'string' && typeof newVal === 'string') {
|
|
121
129
|
// concat logic
|
|
@@ -136,18 +144,18 @@ mergeAndCompare(concatStrings, { name: 'John' }, { name: 'Simth' })
|
|
|
136
144
|
Be careful for JavaScript object reference. Any property that's nested will be reactive and linked between the original and the merged objects! Down below we'll show how to prevent this.
|
|
137
145
|
|
|
138
146
|
```js
|
|
139
|
-
const original = { airport: {
|
|
147
|
+
const original = { airport: { status: 'dep. 🛫' } }
|
|
140
148
|
const extraInfo = { airport: { location: 'Brussels' } }
|
|
141
149
|
const merged = merge(original, extraInfo)
|
|
142
150
|
|
|
143
|
-
// we change the
|
|
144
|
-
merged.airport.
|
|
151
|
+
// we change the status from departuring 🛫 to landing 🛬
|
|
152
|
+
merged.airport.status = 'lan. 🛬'
|
|
145
153
|
|
|
146
154
|
// the `merged` value will be modified
|
|
147
|
-
// merged.airport.
|
|
155
|
+
// merged.airport.status === 'lan. 🛬'
|
|
148
156
|
|
|
149
157
|
// However `original` value will also be modified!!
|
|
150
|
-
// original.airport.
|
|
158
|
+
// original.airport.status === 'lan. 🛬'
|
|
151
159
|
```
|
|
152
160
|
|
|
153
161
|
The key rule to remember is:
|
|
@@ -161,15 +169,15 @@ See below how we integrate 'copy-anything':
|
|
|
161
169
|
```js
|
|
162
170
|
import copy from 'copy-anything'
|
|
163
171
|
|
|
164
|
-
const original = { airport: {
|
|
172
|
+
const original = { airport: { status: 'dep. 🛫' } }
|
|
165
173
|
const extraInfo = { airport: { location: 'Brussels' } }
|
|
166
174
|
const merged = copy(merge(original, extraInfo))
|
|
167
175
|
|
|
168
|
-
// we change the
|
|
169
|
-
merged.airport.
|
|
176
|
+
// we change the status from departuring 🛫 to landing 🛬
|
|
177
|
+
merged.airport.status = 'lan. 🛬'(merged.airport.status === 'lan. 🛬')(
|
|
170
178
|
// true
|
|
171
179
|
// `original` won't be modified!
|
|
172
|
-
original.airport.
|
|
180
|
+
original.airport.status === 'dep. 🛫'
|
|
173
181
|
) // true
|
|
174
182
|
```
|
|
175
183
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var isWhat = require('is-what');
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
8
|
+
function concatArrays(originVal, newVal) {
|
|
9
|
+
if (isWhat.isArray(originVal) && isWhat.isArray(newVal)) {
|
|
10
|
+
// concat logic
|
|
11
|
+
return originVal.concat(newVal);
|
|
12
|
+
}
|
|
13
|
+
return newVal; // always return newVal as fallback!!
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function assignProp(carry, key, newVal, originalObject) {
|
|
17
|
+
const propType = {}.propertyIsEnumerable.call(originalObject, key)
|
|
18
|
+
? 'enumerable'
|
|
19
|
+
: 'nonenumerable';
|
|
20
|
+
if (propType === 'enumerable')
|
|
21
|
+
carry[key] = newVal;
|
|
22
|
+
if (propType === 'nonenumerable') {
|
|
23
|
+
Object.defineProperty(carry, key, {
|
|
24
|
+
value: newVal,
|
|
25
|
+
enumerable: false,
|
|
26
|
+
writable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function mergeRecursively(origin, newComer, compareFn) {
|
|
32
|
+
// always return newComer if its not an object
|
|
33
|
+
if (!isWhat.isPlainObject(newComer))
|
|
34
|
+
return newComer;
|
|
35
|
+
// define newObject to merge all values upon
|
|
36
|
+
let newObject = {};
|
|
37
|
+
if (isWhat.isPlainObject(origin)) {
|
|
38
|
+
const props = Object.getOwnPropertyNames(origin);
|
|
39
|
+
const symbols = Object.getOwnPropertySymbols(origin);
|
|
40
|
+
newObject = [...props, ...symbols].reduce((carry, key) => {
|
|
41
|
+
const targetVal = origin[key];
|
|
42
|
+
if ((!isWhat.isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key)) ||
|
|
43
|
+
(isWhat.isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key))) {
|
|
44
|
+
assignProp(carry, key, targetVal, origin);
|
|
45
|
+
}
|
|
46
|
+
return carry;
|
|
47
|
+
}, {});
|
|
48
|
+
}
|
|
49
|
+
// newObject has all properties that newComer hasn't
|
|
50
|
+
const props = Object.getOwnPropertyNames(newComer);
|
|
51
|
+
const symbols = Object.getOwnPropertySymbols(newComer);
|
|
52
|
+
const result = [...props, ...symbols].reduce((carry, key) => {
|
|
53
|
+
// re-define the origin and newComer as targetVal and newVal
|
|
54
|
+
let newVal = newComer[key];
|
|
55
|
+
const targetVal = isWhat.isPlainObject(origin) ? origin[key] : undefined;
|
|
56
|
+
// When newVal is an object do the merge recursively
|
|
57
|
+
if (targetVal !== undefined && isWhat.isPlainObject(newVal)) {
|
|
58
|
+
newVal = mergeRecursively(targetVal, newVal, compareFn);
|
|
59
|
+
}
|
|
60
|
+
const propToAssign = compareFn ? compareFn(targetVal, newVal, key) : newVal;
|
|
61
|
+
assignProp(carry, key, propToAssign, newComer);
|
|
62
|
+
return carry;
|
|
63
|
+
}, newObject);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Merge anything recursively.
|
|
68
|
+
* Objects get merged, special objects (classes etc.) are re-assigned "as is".
|
|
69
|
+
* Basic types overwrite objects or other basic types.
|
|
70
|
+
* @param object
|
|
71
|
+
* @param otherObjects
|
|
72
|
+
*/
|
|
73
|
+
function merge(object, ...otherObjects) {
|
|
74
|
+
return otherObjects.reduce((result, newComer) => {
|
|
75
|
+
return mergeRecursively(result, newComer);
|
|
76
|
+
}, object);
|
|
77
|
+
}
|
|
78
|
+
function mergeAndCompare(compareFn, object, ...otherObjects) {
|
|
79
|
+
return otherObjects.reduce((result, newComer) => {
|
|
80
|
+
return mergeRecursively(result, newComer, compareFn);
|
|
81
|
+
}, object);
|
|
82
|
+
}
|
|
83
|
+
function mergeAndConcat(object, ...otherObjects) {
|
|
84
|
+
return otherObjects.reduce((result, newComer) => {
|
|
85
|
+
return mergeRecursively(result, newComer, concatArrays);
|
|
86
|
+
}, object);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.concatArrays = concatArrays;
|
|
90
|
+
exports.merge = merge;
|
|
91
|
+
exports.mergeAndCompare = mergeAndCompare;
|
|
92
|
+
exports.mergeAndConcat = mergeAndConcat;
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isArray, isPlainObject, isSymbol } from 'is-what';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
4
|
+
function concatArrays(originVal, newVal) {
|
|
5
|
+
if (isArray(originVal) && isArray(newVal)) {
|
|
6
|
+
// concat logic
|
|
7
|
+
return originVal.concat(newVal);
|
|
8
|
+
}
|
|
9
|
+
return newVal; // always return newVal as fallback!!
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function assignProp(carry, key, newVal, originalObject) {
|
|
13
|
+
const propType = {}.propertyIsEnumerable.call(originalObject, key)
|
|
14
|
+
? 'enumerable'
|
|
15
|
+
: 'nonenumerable';
|
|
16
|
+
if (propType === 'enumerable')
|
|
17
|
+
carry[key] = newVal;
|
|
18
|
+
if (propType === 'nonenumerable') {
|
|
19
|
+
Object.defineProperty(carry, key, {
|
|
20
|
+
value: newVal,
|
|
21
|
+
enumerable: false,
|
|
22
|
+
writable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function mergeRecursively(origin, newComer, compareFn) {
|
|
28
|
+
// always return newComer if its not an object
|
|
29
|
+
if (!isPlainObject(newComer))
|
|
30
|
+
return newComer;
|
|
31
|
+
// define newObject to merge all values upon
|
|
32
|
+
let newObject = {};
|
|
33
|
+
if (isPlainObject(origin)) {
|
|
34
|
+
const props = Object.getOwnPropertyNames(origin);
|
|
35
|
+
const symbols = Object.getOwnPropertySymbols(origin);
|
|
36
|
+
newObject = [...props, ...symbols].reduce((carry, key) => {
|
|
37
|
+
const targetVal = origin[key];
|
|
38
|
+
if ((!isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key)) ||
|
|
39
|
+
(isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key))) {
|
|
40
|
+
assignProp(carry, key, targetVal, origin);
|
|
41
|
+
}
|
|
42
|
+
return carry;
|
|
43
|
+
}, {});
|
|
44
|
+
}
|
|
45
|
+
// newObject has all properties that newComer hasn't
|
|
46
|
+
const props = Object.getOwnPropertyNames(newComer);
|
|
47
|
+
const symbols = Object.getOwnPropertySymbols(newComer);
|
|
48
|
+
const result = [...props, ...symbols].reduce((carry, key) => {
|
|
49
|
+
// re-define the origin and newComer as targetVal and newVal
|
|
50
|
+
let newVal = newComer[key];
|
|
51
|
+
const targetVal = isPlainObject(origin) ? origin[key] : undefined;
|
|
52
|
+
// When newVal is an object do the merge recursively
|
|
53
|
+
if (targetVal !== undefined && isPlainObject(newVal)) {
|
|
54
|
+
newVal = mergeRecursively(targetVal, newVal, compareFn);
|
|
55
|
+
}
|
|
56
|
+
const propToAssign = compareFn ? compareFn(targetVal, newVal, key) : newVal;
|
|
57
|
+
assignProp(carry, key, propToAssign, newComer);
|
|
58
|
+
return carry;
|
|
59
|
+
}, newObject);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Merge anything recursively.
|
|
64
|
+
* Objects get merged, special objects (classes etc.) are re-assigned "as is".
|
|
65
|
+
* Basic types overwrite objects or other basic types.
|
|
66
|
+
* @param object
|
|
67
|
+
* @param otherObjects
|
|
68
|
+
*/
|
|
69
|
+
function merge(object, ...otherObjects) {
|
|
70
|
+
return otherObjects.reduce((result, newComer) => {
|
|
71
|
+
return mergeRecursively(result, newComer);
|
|
72
|
+
}, object);
|
|
73
|
+
}
|
|
74
|
+
function mergeAndCompare(compareFn, object, ...otherObjects) {
|
|
75
|
+
return otherObjects.reduce((result, newComer) => {
|
|
76
|
+
return mergeRecursively(result, newComer, compareFn);
|
|
77
|
+
}, object);
|
|
78
|
+
}
|
|
79
|
+
function mergeAndConcat(object, ...otherObjects) {
|
|
80
|
+
return otherObjects.reduce((result, newComer) => {
|
|
81
|
+
return mergeRecursively(result, newComer, concatArrays);
|
|
82
|
+
}, object);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { concatArrays, merge, mergeAndCompare, mergeAndConcat };
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { O } from 'ts-toolbelt';
|
|
2
|
+
/**
|
|
3
|
+
* Merge anything recursively.
|
|
4
|
+
* Objects get merged, special objects (classes etc.) are re-assigned "as is".
|
|
5
|
+
* Basic types overwrite objects or other basic types.
|
|
6
|
+
* @param object
|
|
7
|
+
* @param otherObjects
|
|
8
|
+
*/
|
|
9
|
+
export declare function merge<T extends Record<string, any>, Tn extends Record<string, any>[]>(object: T, ...otherObjects: Tn): O.Assign<T, Tn, 'deep'>;
|
|
10
|
+
export declare function mergeAndCompare<T extends Record<string, any>, Tn extends Record<string, any>[]>(compareFn: (prop1: any, prop2: any, propName: string | symbol) => any, object: T, ...otherObjects: Tn): O.Assign<T, Tn, 'deep'>;
|
|
11
|
+
export declare function mergeAndConcat<T extends Record<string, any>, Tn extends Record<string, any>[]>(object: T, ...otherObjects: Tn): O.Assign<T, Tn, 'deep'>;
|
package/package.json
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "merge-anything",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
+
"type": "module",
|
|
5
6
|
"description": "Merge objects & other types recursively. A simple & small integration.",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"module": "./dist/index.es.js",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.es.js",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"types": "./dist/types/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=12.13",
|
|
22
|
+
"npm": ">=7"
|
|
23
|
+
},
|
|
9
24
|
"scripts": {
|
|
10
|
-
"lint": "eslint src
|
|
11
|
-
"test": "
|
|
12
|
-
"
|
|
13
|
-
"
|
|
25
|
+
"lint": "tsc --noEmit && eslint ./src --ext .ts",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"build": "rollup -c ./scripts/build.js",
|
|
28
|
+
"release": "npm run lint && del dist && npm run build && np"
|
|
14
29
|
},
|
|
15
30
|
"repository": {
|
|
16
31
|
"type": "git",
|
|
@@ -39,33 +54,59 @@
|
|
|
39
54
|
"nested-combine"
|
|
40
55
|
],
|
|
41
56
|
"author": "Luca Ban - Mesqueeb",
|
|
57
|
+
"funding": "https://github.com/sponsors/mesqueeb",
|
|
42
58
|
"license": "MIT",
|
|
43
59
|
"bugs": {
|
|
44
60
|
"url": "https://github.com/mesqueeb/merge-anything/issues"
|
|
45
61
|
},
|
|
46
62
|
"homepage": "https://github.com/mesqueeb/merge-anything#readme",
|
|
47
63
|
"dependencies": {
|
|
48
|
-
"is-what": "^
|
|
49
|
-
"ts-toolbelt": "^6.
|
|
64
|
+
"is-what": "^4.1.1",
|
|
65
|
+
"ts-toolbelt": "^9.6.0"
|
|
50
66
|
},
|
|
51
67
|
"devDependencies": {
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
53
|
-
"@typescript-eslint/parser": "^
|
|
54
|
-
"
|
|
55
|
-
"eslint": "^
|
|
56
|
-
"eslint-config-prettier": "^
|
|
57
|
-
"eslint-plugin-tree-shaking": "^1.
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
|
69
|
+
"@typescript-eslint/parser": "^5.10.1",
|
|
70
|
+
"del-cli": "^4.0.1",
|
|
71
|
+
"eslint": "^8.7.0",
|
|
72
|
+
"eslint-config-prettier": "^8.3.0",
|
|
73
|
+
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
74
|
+
"np": "^7.6.0",
|
|
75
|
+
"prettier": "^2.5.1",
|
|
76
|
+
"rollup": "^2.66.0",
|
|
77
|
+
"rollup-plugin-typescript2": "^0.31.1",
|
|
78
|
+
"typescript": "^4.5.5",
|
|
79
|
+
"vitest": "^0.2.1"
|
|
62
80
|
},
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
81
|
+
"np": {
|
|
82
|
+
"yarn": false,
|
|
83
|
+
"branch": "production"
|
|
84
|
+
},
|
|
85
|
+
"eslintConfig": {
|
|
86
|
+
"ignorePatterns": [
|
|
87
|
+
"node_modules",
|
|
88
|
+
"dist",
|
|
89
|
+
"scripts",
|
|
90
|
+
"test"
|
|
91
|
+
],
|
|
92
|
+
"root": true,
|
|
93
|
+
"parser": "@typescript-eslint/parser",
|
|
94
|
+
"plugins": [
|
|
95
|
+
"@typescript-eslint",
|
|
96
|
+
"tree-shaking"
|
|
97
|
+
],
|
|
98
|
+
"extends": [
|
|
99
|
+
"eslint:recommended",
|
|
100
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
101
|
+
"plugin:@typescript-eslint/recommended",
|
|
102
|
+
"prettier"
|
|
66
103
|
],
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
|
|
104
|
+
"rules": {
|
|
105
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
106
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
107
|
+
"@typescript-eslint/ban-ts-ignore": "off",
|
|
108
|
+
"tree-shaking/no-side-effects-in-initialization": "error",
|
|
109
|
+
"@typescript-eslint/ban-ts-comment": "off"
|
|
110
|
+
}
|
|
70
111
|
}
|
|
71
112
|
}
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,17 +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
|
-
}
|
|
17
|
-
}
|
package/.github/FUNDING.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# These are supported funding model platforms
|
|
2
|
-
|
|
3
|
-
github: mesqueeb
|
|
4
|
-
patreon: # Replace with a single Patreon username
|
|
5
|
-
open_collective: # Replace with a single Open Collective username
|
|
6
|
-
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
-
liberapay: # Replace with a single Liberapay username
|
|
10
|
-
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
-
otechie: # Replace with a single Otechie username
|
|
12
|
-
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
|
Binary file
|
package/.prettierrc
DELETED
package/_playground.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { OptionalDeep } from 'Object/Optional'
|
|
2
|
-
import {O} from 'ts-toolbelt'
|
|
3
|
-
|
|
4
|
-
type merge = O.Assign<
|
|
5
|
-
{ obj: string, num: number, nested: { values: number[] } },
|
|
6
|
-
[{ obj: Record<string, any> }]
|
|
7
|
-
>
|
|
8
|
-
|
|
9
|
-
interface MyObject { someVal: string }
|
|
10
|
-
interface MyType { array?: MyObject[] }
|
|
11
|
-
|
|
12
|
-
const defaults: MyType = {
|
|
13
|
-
array: []
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type Merged = O.Assign<typeof defaults, [OptionalDeep<MyType>], "deep">
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
interface GoogleStudent {
|
|
20
|
-
googleUserId: string
|
|
21
|
-
}
|
|
22
|
-
interface Test {
|
|
23
|
-
googleStudents?: GoogleStudent[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type N = O.Assign<Test, [O.Partial<Test, "deep">], "deep">
|
|
27
|
-
|
package/build/rollup.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
// npm i -D rollup-plugin-typescript2 typescript
|
|
4
|
-
import typescript from 'rollup-plugin-typescript2'
|
|
5
|
-
|
|
6
|
-
// ------------------------------------------------------------------------------------------
|
|
7
|
-
// formats
|
|
8
|
-
// ------------------------------------------------------------------------------------------
|
|
9
|
-
// amd – Asynchronous Module Definition, used with module loaders like RequireJS
|
|
10
|
-
// cjs – CommonJS, suitable for Node and Browserify/Webpack
|
|
11
|
-
// esm – Keep the bundle as an ES module file
|
|
12
|
-
// iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
|
|
13
|
-
// umd – Universal Module Definition, works as amd, cjs and iife all in one
|
|
14
|
-
// system – Native format of the SystemJS loader
|
|
15
|
-
|
|
16
|
-
// ------------------------------------------------------------------------------------------
|
|
17
|
-
// setup
|
|
18
|
-
// ------------------------------------------------------------------------------------------
|
|
19
|
-
const pkg = require('../package.json')
|
|
20
|
-
const name = pkg.name
|
|
21
|
-
const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
|
|
22
|
-
const external = Object.keys(pkg.dependencies || [])
|
|
23
|
-
const plugins = [typescript({ useTsconfigDeclarationDir: true })]
|
|
24
|
-
|
|
25
|
-
// ------------------------------------------------------------------------------------------
|
|
26
|
-
// Builds
|
|
27
|
-
// ------------------------------------------------------------------------------------------
|
|
28
|
-
function defaults (config) {
|
|
29
|
-
// defaults
|
|
30
|
-
const defaults = {
|
|
31
|
-
plugins,
|
|
32
|
-
external,
|
|
33
|
-
}
|
|
34
|
-
// defaults.output
|
|
35
|
-
config.output = config.output.map(output => {
|
|
36
|
-
return Object.assign(
|
|
37
|
-
{
|
|
38
|
-
sourcemap: false,
|
|
39
|
-
name: className,
|
|
40
|
-
},
|
|
41
|
-
output
|
|
42
|
-
)
|
|
43
|
-
})
|
|
44
|
-
return Object.assign(defaults, config)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default [
|
|
48
|
-
defaults({
|
|
49
|
-
input: 'src/index.ts',
|
|
50
|
-
output: [
|
|
51
|
-
{ file: 'dist/index.cjs.js', format: 'cjs' },
|
|
52
|
-
{ file: 'dist/index.esm.js', format: 'esm' },
|
|
53
|
-
],
|
|
54
|
-
}),
|
|
55
|
-
]
|