objects.ts 577 B

12345678910111213141516171819202122
  1. import { get, set } from 'lodash-unified'
  2. import type { Entries } from 'type-fest'
  3. import type { Arrayable } from '.'
  4. export const keysOf = <T>(arr: T) => Object.keys(arr) as Array<keyof T>
  5. export const entriesOf = <T>(arr: T) => Object.entries(arr) as Entries<T>
  6. export { hasOwn } from '@vue/shared'
  7. export const getProp = <T = any>(
  8. obj: Record<string, any>,
  9. path: Arrayable<string>,
  10. defaultValue?: any
  11. ): { value: T } => {
  12. return {
  13. get value() {
  14. return get(obj, path, defaultValue)
  15. },
  16. set value(val: any) {
  17. set(obj, path, val)
  18. },
  19. }
  20. }