{"version":3,"file":"get-DviPilha.cjs","names":["isArray","hasKey"],"sources":["../src/functions/get/get.ts"],"sourcesContent":["import type { Get } from 'type-fest';\n\nimport type { Many, ObjectPath } from '../../types';\nimport { hasKey } from '../hasKey';\nimport { isArray } from '../isArray';\n\n/**\n * Gets the value at path of object.\n * Allows accessing properties in unions of objects and getting undefined if the property is not present.\n * @param object The object to query.\n * @param path The path of the property to get.\n * @returns The value at path of object.\n * @example\n * ```ts\n * get({ a: 1, b: 2, c: 3 }, 'b') // 2\n * get({\n *   name: \"John Doe\",\n *   address: {\n *     street: \"123 Main St\",\n *     city: \"Anytown\",\n *   }\n * }, 'address.city') // \"Anytown\"\n * ```\n */\nexport function get<T, Path extends ObjectPath<T>>(\n  object: T,\n  path: Path\n): Get<T, Path>;\n/**\n * Gets the value at path of object.\n * Allows accessing properties in unions of objects and getting undefined if the property is not present.\n * @param object The object to query.\n * @param path The path of the property to get.\n * @returns The value at path of object.\n * @example\n * ```ts\n * get({\n *   name: \"John Doe\",\n *   address: {\n *     street: \"123 Main St\",\n *     city: \"Anytown\",\n *   }\n * }, ['address', 'city']) // \"Anytown\"\n * ```\n */\nexport function get<T, Path extends Many<string>>(\n  object: T,\n  path: Path\n): Get<T, Path>;\n/**\n * Implementation of all overloads.\n * @param object The object to query.\n * @param path The path of the property to get.\n * @returns The value at path of object.\n */\nexport function get<T, Path extends ObjectPath<T> | 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    return undefined;\n  }, object as object) as Get<T, Path>;\n}\n"],"mappings":";;;;;;;;;;AAuDA,SAAgB,IACd,QACA,MACc;AAGd,SAFgCA,wBAAQ,KAAK,GAAG,OAAO,KAAK,MAAM,IAAI,EAE1D,QAAiB,OAAO,QAAQ;AAC1C,MAAIC,sBAAO,OAAiB,IAAI,CAC9B,QAAQ,MAAsC;IAI/C,OAAiB"}