2022-03-06 22:20:56 +08:00
|
|
|
import { get, set } from 'lodash-unified'
|
2022-02-11 11:03:15 +08:00
|
|
|
import type { Entries } from 'type-fest'
|
2022-03-06 22:20:56 +08:00
|
|
|
import type { Arrayable } from '.'
|
2022-02-11 11:03:15 +08:00
|
|
|
|
|
|
|
export const keysOf = <T>(arr: T) => Object.keys(arr) as Array<keyof T>
|
|
|
|
export const entriesOf = <T>(arr: T) => Object.entries(arr) as Entries<T>
|
|
|
|
export { hasOwn } from '@vue/shared'
|
|
|
|
|
2022-03-06 22:20:56 +08:00
|
|
|
export const getProp = <T = any>(
|
|
|
|
obj: Record<string, any>,
|
|
|
|
path: Arrayable<string>,
|
|
|
|
defaultValue?: any
|
|
|
|
): { value: T } => {
|
2022-02-11 11:03:15 +08:00
|
|
|
return {
|
2022-03-06 22:20:56 +08:00
|
|
|
get value() {
|
|
|
|
return get(obj, path, defaultValue)
|
|
|
|
},
|
|
|
|
set value(val: any) {
|
|
|
|
set(obj, path, val)
|
|
|
|
},
|
2022-02-11 11:03:15 +08:00
|
|
|
}
|
|
|
|
}
|