feat(utils): getPropByPath function adjust (#1276)

Co-authored-by: 三咲智子 <sxzz@sxzz.moe>
This commit is contained in:
jectychen 2021-09-13 03:14:47 +08:00 committed by GitHub
parent 00d38e1807
commit 4d3a499fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,6 +49,12 @@ export function getPropByPath(
v: Nullable<unknown>
} {
let tempObj = obj
let key, value
if (obj && hasOwn(obj, path)) {
key = path
value = tempObj?.[path]
} else {
path = path.replace(/\[(\w+)\]/g, '.$1')
path = path.replace(/^\./, '')
@ -67,10 +73,13 @@ export function getPropByPath(
break
}
}
key = keyArr[i]
value = tempObj?.[keyArr[i]]
}
return {
o: tempObj,
k: keyArr[i],
v: tempObj?.[keyArr[i]],
k: key,
v: value,
}
}