{"version":3,"sources":["../../src/functions/hasKey/hasKey.ts","../../src/functions/isArray/isArray.ts","../../src/functions/get/get.ts"],"names":[],"mappings":";AAEO,SAAS,OAGd,OAAU,KAAyC;AACnD,MAAI,OAAO,UAAU,YAAY,SAAS,MAAM;AAC9C,WAAO;AAAA,EACT;AAEA,SAAO,OAAO;AAChB;;;ACLO,IAAM,UAAmB,MAAM;;;ACK/B,SAAS,IACd,QACA,MACc;AACd,QAAM,OAA0B,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG;AAErE,SAAO,KAAK,OAAgB,CAAC,OAAO,QAAQ;AAC1C,QAAI,OAAO,OAAiB,GAAG,GAAG;AAChC,aAAQ,MAAsC,GAAG;AAAA,IACnD;AAGA,WAAO;AAAA,EACT,GAAG,MAAgB;AACrB","sourcesContent":["import { KeysOfUnion, StringWithAutocomplete } from '../../types';\n\nexport function hasKey<\n  T extends object,\n  K extends StringWithAutocomplete<KeysOfUnion<T> & string> | PropertyKey\n>(value: T, key: K): value is T & Record<K, unknown> {\n  if (typeof value !== 'object' || value == null) {\n    return false;\n  }\n\n  return key in value;\n}\n","import { Many } from '../../types';\n\n/**\n * The same as `Array.isArray` but with a better type guard.\n */\n// eslint-disable-next-line prefer-destructuring\nexport const isArray: IsArray = Array.isArray;\n\ninterface IsArray {\n  <T>(value: Many<T>): value is readonly T[];\n  <T>(value: unknown): value is readonly T[];\n}\n","import type { Get } from 'type-fest';\n\nimport { Many } from '../../types';\nimport { hasKey } from '../hasKey';\nimport { isArray } from '../isArray';\n\n/**\n * Gets the value at path of object.\n *\n * Allows accessing properties in unions of objects and getting undefined if the property is not present.\n */\nexport function get<T, Path extends Many<string>>(\n  object: T,\n  path: Path\n): Get<T, Path> {\n  const keys: readonly string[] = isArray(path) ? path : path.split('.');\n\n  return keys.reduce<unknown>((value, key) => {\n    if (hasKey(value as object, key)) {\n      return (value as Record<typeof key, unknown>)[key];\n    }\n\n    // eslint-disable-next-line unicorn/no-useless-undefined -- default value, explicitly declare it\n    return undefined;\n  }, object as object) as Get<T, Path>;\n}\n"]}