@nomicfoundation/hardhat-utils 3.0.4 → 3.0.5
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/CHANGELOG.md +6 -0
- package/dist/src/internal/lang.d.ts +1 -1
- package/dist/src/internal/lang.d.ts.map +1 -1
- package/dist/src/internal/lang.js +12 -10
- package/dist/src/internal/lang.js.map +1 -1
- package/dist/src/lang.d.ts +13 -5
- package/dist/src/lang.d.ts.map +1 -1
- package/dist/src/lang.js +14 -6
- package/dist/src/lang.js.map +1 -1
- package/package.json +1 -1
- package/src/internal/lang.ts +21 -16
- package/src/lang.ts +14 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @nomicfoundation/hardhat-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d45234d: Fixed Etherscan verification failures by removing hardcoded v1 API URLs from chain descriptors ([#7623](https://github.com/NomicFoundation/hardhat/issues/7623)). Also enhanced config resolution to support partial overrides in block explorer configurations for future extensibility.
|
|
8
|
+
|
|
3
9
|
## 3.0.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare function getDeepCloneFunction(): Promise<(<T>(input: T) => T)>;
|
|
2
|
-
export declare function deepMergeImpl<T extends object,
|
|
2
|
+
export declare function deepMergeImpl<T extends object, S extends object>(target: T, source: S, shouldOverwriteUndefined: boolean): T & S;
|
|
3
3
|
//# sourceMappingURL=lang.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../../src/internal/lang.ts"],"names":[],"mappings":"AAKA,wBAAsB,oBAAoB,IAAI,OAAO,EAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAC,CAQxE;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC9D,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../../src/internal/lang.ts"],"names":[],"mappings":"AAKA,wBAAsB,oBAAoB,IAAI,OAAO,EAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAC,CAQxE;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC9D,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,EACT,wBAAwB,EAAE,OAAO,GAChC,CAAC,GAAG,CAAC,CAmCP"}
|
|
@@ -7,28 +7,30 @@ export async function getDeepCloneFunction() {
|
|
|
7
7
|
}
|
|
8
8
|
return clone;
|
|
9
9
|
}
|
|
10
|
-
export function deepMergeImpl(target, source) {
|
|
10
|
+
export function deepMergeImpl(target, source, shouldOverwriteUndefined) {
|
|
11
11
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
12
|
-
--
|
|
13
|
-
but initially only target is spread in, so a cast is needed. */
|
|
12
|
+
-- Result will include properties from both T and S, but starts with only T */
|
|
14
13
|
const result = { ...target };
|
|
15
|
-
/*
|
|
16
|
-
-- TypeScript
|
|
14
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
15
|
+
-- All keys come from S, TypeScript can't infer the union of string and symbol keys */
|
|
17
16
|
const keys = [
|
|
18
17
|
...Object.keys(source),
|
|
19
18
|
...Object.getOwnPropertySymbols(source),
|
|
20
19
|
];
|
|
21
20
|
for (const key of keys) {
|
|
22
21
|
if (isObject(source[key]) &&
|
|
23
|
-
// Only merge
|
|
22
|
+
// Only merge plain objects, not class instances
|
|
24
23
|
Object.getPrototypeOf(source[key]) === Object.prototype) {
|
|
25
24
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
26
|
-
--
|
|
27
|
-
result[key] = deepMergeImpl(result[key] ?? {},
|
|
25
|
+
-- result[key] will have the correct type after assignment but TS can't infer it */
|
|
26
|
+
result[key] = deepMergeImpl(result[key] ?? {},
|
|
27
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
28
|
+
-- source[key] is known to be from S but TS can't infer it */
|
|
29
|
+
source[key], shouldOverwriteUndefined);
|
|
28
30
|
}
|
|
29
|
-
else {
|
|
31
|
+
else if (shouldOverwriteUndefined || source[key] !== undefined) {
|
|
30
32
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
31
|
-
--
|
|
33
|
+
-- result[key] will have the correct type after assignment but TS can't infer it */
|
|
32
34
|
result[key] = source[key];
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lang.js","sourceRoot":"","sources":["../../../src/internal/lang.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,IAAI,KAAK,GAAoC,IAAI,CAAC;AAClD,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAE/C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,KAAK,GAAG,IAAI,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,MAAS,EACT,MAAS;
|
|
1
|
+
{"version":3,"file":"lang.js","sourceRoot":"","sources":["../../../src/internal/lang.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,IAAI,KAAK,GAAoC,IAAI,CAAC;AAClD,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAE/C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,KAAK,GAAG,IAAI,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,MAAS,EACT,MAAS,EACT,wBAAiC;IAEjC;kFAC8E;IAC9E,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAW,CAAC;IAEtC;0FACsF;IACtF,MAAM,IAAI,GAAG;QACX,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QACtB,GAAG,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC;KACtB,CAAC;IAEpB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IACE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,gDAAgD;YAChD,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,SAAS,EACvD,CAAC;YACD;+FACmF;YACnF,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa,CACzB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE;YACjB;yEAC6D;YAC7D,MAAM,CAAC,GAAG,CAAM,EAChB,wBAAwB,CACY,CAAC;QACzC,CAAC;aAAM,IAAI,wBAAwB,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YACjE;+FACmF;YACnF,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAsC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/src/lang.d.ts
CHANGED
|
@@ -18,20 +18,28 @@ export declare function deepEqual<T>(x: T, y: T): Promise<boolean>;
|
|
|
18
18
|
*
|
|
19
19
|
* @remarks
|
|
20
20
|
* - Arrays or `undefined` values are not valid inputs.
|
|
21
|
-
* - Functions: If a function exists in both the target and source, the source
|
|
22
|
-
*
|
|
23
|
-
* -
|
|
21
|
+
* - Functions: If a function exists in both the target and source, the source
|
|
22
|
+
* function overwrites the target.
|
|
23
|
+
* - Symbol properties: Symbol-keyed properties are merged just like string
|
|
24
|
+
* keys.
|
|
25
|
+
* - Class instances: Class instances are not merged recursively. If a class
|
|
26
|
+
* instance exists in the source, it will replace the one in the target.
|
|
24
27
|
*
|
|
25
28
|
* @param target The target object to merge into.
|
|
26
29
|
* @param source The source object to merge from.
|
|
30
|
+
* @param shouldOverwriteUndefined If true, properties with `undefined` values
|
|
31
|
+
* in the source will overwrite those in the target. Default is true.
|
|
27
32
|
* @returns A new object containing the deeply merged properties.
|
|
28
33
|
*
|
|
29
34
|
* @example
|
|
30
35
|
* deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // => { a: { b: 1, c: 2 } }
|
|
31
36
|
*
|
|
32
|
-
* deepMerge(
|
|
37
|
+
* deepMerge(
|
|
38
|
+
* { a: { fn: () => "from target" } },
|
|
39
|
+
* { a: { fn: () => "from source" } }
|
|
40
|
+
* ) // => { a: { fn: () => "from source" } }
|
|
33
41
|
*/
|
|
34
|
-
export declare function deepMerge<T extends object, U extends object>(target: T, source: U): T & U;
|
|
42
|
+
export declare function deepMerge<T extends object, U extends object>(target: T, source: U, shouldOverwriteUndefined?: boolean): T & U;
|
|
35
43
|
/**
|
|
36
44
|
* Checks if a value is an object. This function returns false for arrays.
|
|
37
45
|
*
|
package/dist/src/lang.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIvD;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/D;AAED
|
|
1
|
+
{"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIvD;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC1D,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,EACT,wBAAwB,GAAE,OAAc,GACvC,CAAC,GAAG,CAAC,CAEP;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAE3C;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CA4BzE"}
|
package/dist/src/lang.js
CHANGED
|
@@ -25,21 +25,29 @@ export async function deepEqual(x, y) {
|
|
|
25
25
|
*
|
|
26
26
|
* @remarks
|
|
27
27
|
* - Arrays or `undefined` values are not valid inputs.
|
|
28
|
-
* - Functions: If a function exists in both the target and source, the source
|
|
29
|
-
*
|
|
30
|
-
* -
|
|
28
|
+
* - Functions: If a function exists in both the target and source, the source
|
|
29
|
+
* function overwrites the target.
|
|
30
|
+
* - Symbol properties: Symbol-keyed properties are merged just like string
|
|
31
|
+
* keys.
|
|
32
|
+
* - Class instances: Class instances are not merged recursively. If a class
|
|
33
|
+
* instance exists in the source, it will replace the one in the target.
|
|
31
34
|
*
|
|
32
35
|
* @param target The target object to merge into.
|
|
33
36
|
* @param source The source object to merge from.
|
|
37
|
+
* @param shouldOverwriteUndefined If true, properties with `undefined` values
|
|
38
|
+
* in the source will overwrite those in the target. Default is true.
|
|
34
39
|
* @returns A new object containing the deeply merged properties.
|
|
35
40
|
*
|
|
36
41
|
* @example
|
|
37
42
|
* deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // => { a: { b: 1, c: 2 } }
|
|
38
43
|
*
|
|
39
|
-
* deepMerge(
|
|
44
|
+
* deepMerge(
|
|
45
|
+
* { a: { fn: () => "from target" } },
|
|
46
|
+
* { a: { fn: () => "from source" } }
|
|
47
|
+
* ) // => { a: { fn: () => "from source" } }
|
|
40
48
|
*/
|
|
41
|
-
export function deepMerge(target, source) {
|
|
42
|
-
return deepMergeImpl(target, source);
|
|
49
|
+
export function deepMerge(target, source, shouldOverwriteUndefined = true) {
|
|
50
|
+
return deepMergeImpl(target, source, shouldOverwriteUndefined);
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
45
53
|
* Checks if a value is an object. This function returns false for arrays.
|
package/dist/src/lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lang.js","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,KAAQ;IACzC,MAAM,UAAU,GAAG,MAAM,oBAAoB,EAAE,CAAC;IAEhD,OAAO,UAAU,CAAI,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,CAAI,EAAE,CAAI;IAC3C,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAE9D,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"lang.js","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,KAAQ;IACzC,MAAM,UAAU,GAAG,MAAM,oBAAoB,EAAE,CAAC;IAEhD,OAAO,UAAU,CAAI,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,CAAI,EAAE,CAAI;IAC3C,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAE9D,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,SAAS,CACvB,MAAS,EACT,MAAS,EACT,2BAAoC,IAAI;IAExC,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAe;IACzC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAyB,GAAY;IACjE,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,aAAa,GACjB,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAElE,MAAM,IAAI,GAAG,CAAC,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IAEpE;wEACoE;IACpE,MAAM,QAAQ,GAAG,GAAU,CAAC;IAE5B,2FAA2F;IAC3F,MAAM,gBAAgB,GAAG;QACvB,aAAa;QACb,gBAAgB;QAChB,eAAe;QACf,sBAAsB;QACtB,gBAAgB;QAChB,UAAU;QACV,SAAS;KACV,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,OAAO,GAAG,KAAK,UAAU,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACjE,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/internal/lang.ts
CHANGED
|
@@ -13,36 +13,41 @@ export async function getDeepCloneFunction(): Promise<<T>(input: T) => T> {
|
|
|
13
13
|
return clone;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function deepMergeImpl<T extends object,
|
|
16
|
+
export function deepMergeImpl<T extends object, S extends object>(
|
|
17
17
|
target: T,
|
|
18
|
-
source:
|
|
19
|
-
|
|
18
|
+
source: S,
|
|
19
|
+
shouldOverwriteUndefined: boolean,
|
|
20
|
+
): T & S {
|
|
20
21
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
21
|
-
--
|
|
22
|
-
|
|
23
|
-
const result = { ...target } as T & U;
|
|
22
|
+
-- Result will include properties from both T and S, but starts with only T */
|
|
23
|
+
const result = { ...target } as T & S;
|
|
24
24
|
|
|
25
|
-
/*
|
|
26
|
-
-- TypeScript
|
|
25
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
26
|
+
-- All keys come from S, TypeScript can't infer the union of string and symbol keys */
|
|
27
27
|
const keys = [
|
|
28
28
|
...Object.keys(source),
|
|
29
29
|
...Object.getOwnPropertySymbols(source),
|
|
30
|
-
] as Array<keyof
|
|
30
|
+
] as Array<keyof S>;
|
|
31
31
|
|
|
32
32
|
for (const key of keys) {
|
|
33
33
|
if (
|
|
34
34
|
isObject(source[key]) &&
|
|
35
|
-
// Only merge
|
|
35
|
+
// Only merge plain objects, not class instances
|
|
36
36
|
Object.getPrototypeOf(source[key]) === Object.prototype
|
|
37
37
|
) {
|
|
38
38
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
39
|
-
--
|
|
40
|
-
result[key] = deepMergeImpl(
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
-- result[key] will have the correct type after assignment but TS can't infer it */
|
|
40
|
+
result[key] = deepMergeImpl(
|
|
41
|
+
result[key] ?? {},
|
|
42
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
43
|
+
-- source[key] is known to be from S but TS can't infer it */
|
|
44
|
+
source[key] as S,
|
|
45
|
+
shouldOverwriteUndefined,
|
|
46
|
+
) as (T & S)[Extract<keyof S, string>];
|
|
47
|
+
} else if (shouldOverwriteUndefined || source[key] !== undefined) {
|
|
43
48
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
44
|
-
--
|
|
45
|
-
result[key] = source[key] as (T &
|
|
49
|
+
-- result[key] will have the correct type after assignment but TS can't infer it */
|
|
50
|
+
result[key] = source[key] as (T & S)[Extract<keyof S, string>];
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
|
package/src/lang.ts
CHANGED
|
@@ -30,24 +30,33 @@ export async function deepEqual<T>(x: T, y: T): Promise<boolean> {
|
|
|
30
30
|
*
|
|
31
31
|
* @remarks
|
|
32
32
|
* - Arrays or `undefined` values are not valid inputs.
|
|
33
|
-
* - Functions: If a function exists in both the target and source, the source
|
|
34
|
-
*
|
|
35
|
-
* -
|
|
33
|
+
* - Functions: If a function exists in both the target and source, the source
|
|
34
|
+
* function overwrites the target.
|
|
35
|
+
* - Symbol properties: Symbol-keyed properties are merged just like string
|
|
36
|
+
* keys.
|
|
37
|
+
* - Class instances: Class instances are not merged recursively. If a class
|
|
38
|
+
* instance exists in the source, it will replace the one in the target.
|
|
36
39
|
*
|
|
37
40
|
* @param target The target object to merge into.
|
|
38
41
|
* @param source The source object to merge from.
|
|
42
|
+
* @param shouldOverwriteUndefined If true, properties with `undefined` values
|
|
43
|
+
* in the source will overwrite those in the target. Default is true.
|
|
39
44
|
* @returns A new object containing the deeply merged properties.
|
|
40
45
|
*
|
|
41
46
|
* @example
|
|
42
47
|
* deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // => { a: { b: 1, c: 2 } }
|
|
43
48
|
*
|
|
44
|
-
* deepMerge(
|
|
49
|
+
* deepMerge(
|
|
50
|
+
* { a: { fn: () => "from target" } },
|
|
51
|
+
* { a: { fn: () => "from source" } }
|
|
52
|
+
* ) // => { a: { fn: () => "from source" } }
|
|
45
53
|
*/
|
|
46
54
|
export function deepMerge<T extends object, U extends object>(
|
|
47
55
|
target: T,
|
|
48
56
|
source: U,
|
|
57
|
+
shouldOverwriteUndefined: boolean = true,
|
|
49
58
|
): T & U {
|
|
50
|
-
return deepMergeImpl(target, source);
|
|
59
|
+
return deepMergeImpl(target, source, shouldOverwriteUndefined);
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
/**
|