-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve options deep copy issue in deepMerge function
- Loading branch information
Showing
9 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
# example | ||
|
||
## 0.4.3 | ||
|
||
### Patch Changes | ||
|
||
- Updated dependencies | ||
- [email protected] | ||
|
||
## 0.4.2 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "cesium-wind-layer", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export function deepMerge<T extends Record<string, any>>(from: Partial<T>, to: T): T { | ||
// Handle null or undefined cases | ||
if (!from) return to; | ||
if (!to) return from as T; | ||
|
||
// Create a new object to avoid modifying the original | ||
const result = { ...to }; | ||
|
||
for (const key in from) { | ||
if (Object.prototype.hasOwnProperty.call(from, key)) { | ||
const fromValue = from[key]; | ||
const toValue = to[key]; | ||
|
||
// Handle array case | ||
if (Array.isArray(fromValue)) { | ||
result[key] = fromValue.slice(); | ||
continue; | ||
} | ||
|
||
// Handle object case | ||
if (fromValue && typeof fromValue === 'object') { | ||
result[key] = deepMerge(fromValue, toValue || {}) as T[Extract<keyof T, string>]; | ||
continue; | ||
} | ||
|
||
// Handle primitive values | ||
if (fromValue !== undefined) { | ||
result[key] = fromValue; | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters