merge-anything 5.1.1 → 5.1.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/dist/index.cjs +30 -3
- package/dist/index.es.js +30 -3
- package/dist/types/merge.d.ts +5 -5
- package/dist/types/typeUtils/List.d.ts +9 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -80,14 +80,41 @@ function mergeAndConcat(object, ...otherObjects) {
|
|
|
80
80
|
return mergeRecursively(result, newComer, concatArrays);
|
|
81
81
|
}, object);
|
|
82
82
|
}
|
|
83
|
-
// import { Timestamp } from '
|
|
83
|
+
// import { Timestamp } from '../test/Timestamp'
|
|
84
84
|
// type T1 = { date: Timestamp }
|
|
85
85
|
// type T2 = [{ b: string[] }, { b: number[] }, { date: Timestamp }]
|
|
86
|
-
// type
|
|
86
|
+
// type TestT = Merge<T1, T2>
|
|
87
87
|
// type A1 = { arr: string[] }
|
|
88
88
|
// type A2 = { arr: number[] }
|
|
89
89
|
// type A3 = { arr: boolean[] }
|
|
90
|
-
// type
|
|
90
|
+
// type TestA = Merge<A1, [A2, A3]>
|
|
91
|
+
// interface I1 {
|
|
92
|
+
// date: Timestamp
|
|
93
|
+
// }
|
|
94
|
+
// interface I2 {
|
|
95
|
+
// date: Timestamp
|
|
96
|
+
// }
|
|
97
|
+
// const _a: I2 = { date: '' } as unknown as I2
|
|
98
|
+
// type TestI = Merge<I1, [I2]>
|
|
99
|
+
// // ReturnType<(typeof merge)<I1, I2>>
|
|
100
|
+
// const a = merge(_a, [_a])
|
|
101
|
+
// interface Arguments extends Record<string | number | symbol, unknown> {
|
|
102
|
+
// key: string;
|
|
103
|
+
// }
|
|
104
|
+
// const aa1: Arguments = { key: "value1" }
|
|
105
|
+
// const aa2: Arguments = { key: "value2" }
|
|
106
|
+
// const aa = merge(a1, a2);
|
|
107
|
+
// interface Barguments {
|
|
108
|
+
// key: string
|
|
109
|
+
// }
|
|
110
|
+
// const ba1: Barguments = { key: 'value1' }
|
|
111
|
+
// const ba2: Barguments = { key: 'value2' }
|
|
112
|
+
// const ba = merge(ba1, ba2)
|
|
113
|
+
// interface Carguments {
|
|
114
|
+
// key: string
|
|
115
|
+
// }
|
|
116
|
+
// const ca = merge<Carguments, Carguments[]>({ key: 'value1' }, { key: 'value2' })
|
|
117
|
+
// type P = Pop<Carguments[]>
|
|
91
118
|
|
|
92
119
|
exports.concatArrays = concatArrays;
|
|
93
120
|
exports.merge = merge;
|
package/dist/index.es.js
CHANGED
|
@@ -78,13 +78,40 @@ function mergeAndConcat(object, ...otherObjects) {
|
|
|
78
78
|
return mergeRecursively(result, newComer, concatArrays);
|
|
79
79
|
}, object);
|
|
80
80
|
}
|
|
81
|
-
// import { Timestamp } from '
|
|
81
|
+
// import { Timestamp } from '../test/Timestamp'
|
|
82
82
|
// type T1 = { date: Timestamp }
|
|
83
83
|
// type T2 = [{ b: string[] }, { b: number[] }, { date: Timestamp }]
|
|
84
|
-
// type
|
|
84
|
+
// type TestT = Merge<T1, T2>
|
|
85
85
|
// type A1 = { arr: string[] }
|
|
86
86
|
// type A2 = { arr: number[] }
|
|
87
87
|
// type A3 = { arr: boolean[] }
|
|
88
|
-
// type
|
|
88
|
+
// type TestA = Merge<A1, [A2, A3]>
|
|
89
|
+
// interface I1 {
|
|
90
|
+
// date: Timestamp
|
|
91
|
+
// }
|
|
92
|
+
// interface I2 {
|
|
93
|
+
// date: Timestamp
|
|
94
|
+
// }
|
|
95
|
+
// const _a: I2 = { date: '' } as unknown as I2
|
|
96
|
+
// type TestI = Merge<I1, [I2]>
|
|
97
|
+
// // ReturnType<(typeof merge)<I1, I2>>
|
|
98
|
+
// const a = merge(_a, [_a])
|
|
99
|
+
// interface Arguments extends Record<string | number | symbol, unknown> {
|
|
100
|
+
// key: string;
|
|
101
|
+
// }
|
|
102
|
+
// const aa1: Arguments = { key: "value1" }
|
|
103
|
+
// const aa2: Arguments = { key: "value2" }
|
|
104
|
+
// const aa = merge(a1, a2);
|
|
105
|
+
// interface Barguments {
|
|
106
|
+
// key: string
|
|
107
|
+
// }
|
|
108
|
+
// const ba1: Barguments = { key: 'value1' }
|
|
109
|
+
// const ba2: Barguments = { key: 'value2' }
|
|
110
|
+
// const ba = merge(ba1, ba2)
|
|
111
|
+
// interface Carguments {
|
|
112
|
+
// key: string
|
|
113
|
+
// }
|
|
114
|
+
// const ca = merge<Carguments, Carguments[]>({ key: 'value1' }, { key: 'value2' })
|
|
115
|
+
// type P = Pop<Carguments[]>
|
|
89
116
|
|
|
90
117
|
export { concatArrays, merge, mergeAndCompare, mergeAndConcat };
|
package/dist/types/merge.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Assign } from './typeUtils/Assign';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Pop } from './typeUtils/List';
|
|
3
3
|
import type { PrettyPrint } from './typeUtils/PrettyPrint';
|
|
4
4
|
/**
|
|
5
5
|
* The return type of `merge()`. It reflects the type that is returned by JavaScript.
|
|
6
6
|
*
|
|
7
7
|
* This TS Utility can be used as standalone as well
|
|
8
8
|
*/
|
|
9
|
-
export declare type Merge<T extends Record<string | number | symbol, unknown
|
|
9
|
+
export declare type Merge<T, Ts extends unknown[]> = T extends Record<string | number | symbol, unknown> ? Ts extends Record<string | number | symbol, unknown>[] ? PrettyPrint<Assign<T, Ts>> : Pop<Ts> : Pop<Ts>;
|
|
10
10
|
/**
|
|
11
11
|
* Merge anything recursively.
|
|
12
12
|
* Objects get merged, special objects (classes etc.) are re-assigned "as is".
|
|
13
13
|
* Basic types overwrite objects or other basic types.
|
|
14
14
|
*/
|
|
15
|
-
export declare function merge<T
|
|
16
|
-
export declare function mergeAndCompare<T
|
|
17
|
-
export declare function mergeAndConcat<T
|
|
15
|
+
export declare function merge<T, Tn extends unknown[]>(object: T, ...otherObjects: Tn): Merge<T, Tn>;
|
|
16
|
+
export declare function mergeAndCompare<T, Tn extends unknown[]>(compareFn: (prop1: any, prop2: any, propName: string | symbol) => any, object: T, ...otherObjects: Tn): Merge<T, Tn>;
|
|
17
|
+
export declare function mergeAndConcat<T, Tn extends unknown[]>(object: T, ...otherObjects: Tn): Merge<T, Tn>;
|
|
@@ -18,3 +18,12 @@ export declare type List<T = any> = readonly T[];
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export declare type Length<L extends List> = L['length'];
|
|
21
|
+
/**
|
|
22
|
+
* Return the last item out of a [[List]]
|
|
23
|
+
* @param L
|
|
24
|
+
* @returns [[List]]
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare type Pop<L extends List> = L extends readonly [] ? never : L extends [...unknown[], infer Last] ? Last : L extends (infer T)[] ? T : never;
|