mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
prepend and append array
This commit is contained in:
parent
344534e4fc
commit
e503095bae
10
changelog.md
10
changelog.md
@ -1,5 +1,7 @@
|
|||||||
### Bug Fixes
|
### Break Changes
|
||||||
|
|
||||||
- 修复便携模式无法启动的问题
|
- YAML覆写语法有所变动,请更新后参考文档进行修改
|
||||||
- 尝试修复Windows系统代理无法打开的问题
|
|
||||||
- 优化Windows程序拉起方式
|
### New Features
|
||||||
|
|
||||||
|
- YAML覆写功能支持对数组进行覆盖/前置/追加操作
|
||||||
|
|||||||
@ -35,12 +35,6 @@ async function overrideProfile(
|
|||||||
break
|
break
|
||||||
case 'yaml': {
|
case 'yaml': {
|
||||||
const patch = yaml.parse(content)
|
const patch = yaml.parse(content)
|
||||||
if (patch.rules) {
|
|
||||||
patch.rules = [...patch.rules, ...(profile.rules || [])]
|
|
||||||
}
|
|
||||||
if (patch.proxies) {
|
|
||||||
patch.proxies = [...patch.proxies, ...(profile.proxies || [])]
|
|
||||||
}
|
|
||||||
profile = deepMerge(profile, patch)
|
profile = deepMerge(profile, patch)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,25 @@ function isObject(item: any): boolean {
|
|||||||
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 (!target[key]) Object.assign(target, { [key]: {} })
|
if (key.endsWith('!')) {
|
||||||
deepMerge(target[key] as object, other[key] as object)
|
const k = key.slice(0, -1)
|
||||||
|
target[k] = other[key]
|
||||||
|
} else {
|
||||||
|
if (!target[key]) Object.assign(target, { [key]: {} })
|
||||||
|
deepMerge(target[key] as object, other[key] as object)
|
||||||
|
}
|
||||||
|
} else if (Array.isArray(other[key])) {
|
||||||
|
if (key.startsWith('+')) {
|
||||||
|
const k = key.slice(1)
|
||||||
|
if (!target[k]) Object.assign(target, { [k]: [] })
|
||||||
|
target[k] = [...other[key], ...(target[k] as never[])]
|
||||||
|
} else if (key.endsWith('+')) {
|
||||||
|
const k = key.slice(0, -1)
|
||||||
|
if (!target[k]) Object.assign(target, { [k]: [] })
|
||||||
|
target[k] = [...(target[k] as never[]), ...other[key]]
|
||||||
|
} else {
|
||||||
|
Object.assign(target, { [key]: 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