mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
correction of merge syntax
This commit is contained in:
parent
b1e39ab4b3
commit
e7ba8e7739
@ -3,27 +3,36 @@ function isObject(item: any): boolean {
|
|||||||
return item && typeof item === 'object' && !Array.isArray(item)
|
return item && typeof item === 'object' && !Array.isArray(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trimWrap(str: string): string {
|
||||||
|
if (str.startsWith('<') && str.endsWith('>')) {
|
||||||
|
return str.slice(1, -1)
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
export function deepMerge<T extends object>(target: T, other: Partial<T>): T {
|
export function deepMerge<T extends object>(target: T, other: Partial<T>): T {
|
||||||
for (const key in other) {
|
for (const key in other) {
|
||||||
if (isObject(other[key])) {
|
if (isObject(other[key])) {
|
||||||
if (key.endsWith('!')) {
|
if (key.endsWith('!')) {
|
||||||
const k = key.slice(0, -1)
|
const k = trimWrap(key.slice(0, -1))
|
||||||
target[k] = other[key]
|
target[k] = other[key]
|
||||||
} else {
|
} else {
|
||||||
if (!target[key]) Object.assign(target, { [key]: {} })
|
const k = trimWrap(key)
|
||||||
deepMerge(target[key] as object, other[key] as object)
|
if (!target[k]) Object.assign(target, { [k]: {} })
|
||||||
|
deepMerge(target[k] as object, other[k] as object)
|
||||||
}
|
}
|
||||||
} else if (Array.isArray(other[key])) {
|
} else if (Array.isArray(other[key])) {
|
||||||
if (key.startsWith('+')) {
|
if (key.startsWith('+')) {
|
||||||
const k = key.slice(1)
|
const k = trimWrap(key.slice(1))
|
||||||
if (!target[k]) Object.assign(target, { [k]: [] })
|
if (!target[k]) Object.assign(target, { [k]: [] })
|
||||||
target[k] = [...other[key], ...(target[k] as never[])]
|
target[k] = [...other[key], ...(target[k] as never[])]
|
||||||
} else if (key.endsWith('+')) {
|
} else if (key.endsWith('+')) {
|
||||||
const k = key.slice(0, -1)
|
const k = trimWrap(key.slice(0, -1))
|
||||||
if (!target[k]) Object.assign(target, { [k]: [] })
|
if (!target[k]) Object.assign(target, { [k]: [] })
|
||||||
target[k] = [...(target[k] as never[]), ...other[key]]
|
target[k] = [...(target[k] as never[]), ...other[key]]
|
||||||
} else {
|
} else {
|
||||||
Object.assign(target, { [key]: other[key] })
|
const k = trimWrap(key)
|
||||||
|
Object.assign(target, { [k]: other[key] })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Object.assign(target, { [key]: other[key] })
|
Object.assign(target, { [key]: other[key] })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user