zgg-ui
Version:
2.0.1 正式版本 基于 Vue 3、UniApp 和 TypeScript 开发的多端适配移动端 UI 组件库,旨在提供丰富的组件集合,帮助开发者快速构建多端响应式的移动应用界面
23 lines (17 loc) • 660 B
text/typescript
import { isKey } from './_isKey'
import { castPath } from './_castPath'
import { toKey } from './_toKey'
import type { PropertyPath } from './_common'
function baseGet(object: any, path: PropertyPath) {
path = isKey(path, object) ? [path] : castPath(path)
let index = 0
const length = path.length
while (object != null && index < length) {
object = object[toKey(path[index++])]
}
return index && index == length ? object : undefined
}
export function get(object: any, path: PropertyPath, defaultValue?: any): any {
const result = object == null ? undefined : baseGet(object, path)
return result === undefined ? defaultValue : result
}