{"version":3,"file":"get.cjs","names":[],"sources":["../../src/object/get.ts"],"sourcesContent":["/**\n * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.\n * @param obj - The object to query\n * @param path - The path of the property to get (can be string or array)\n * @param defaultValue - The value returned if the resolved value is undefined\n * @returns Returns the resolved value\n * @example\n * const obj = { a: { b: { c: 3 } } };\n * get(obj, 'a.b.c'); // 3\n * get(obj, ['a', 'b', 'c']); // 3\n * get(obj, 'a.b.d', 'default'); // 'default'\n */\nexport function get<T = unknown, D = undefined>(\n  obj: unknown,\n  path: string | readonly (string | number)[],\n  defaultValue?: D,\n): T | D {\n  if (obj == null) {\n    return defaultValue as T | D;\n  }\n\n  // Convert string path to array\n  const pathArray: (string | number)[] =\n    typeof path === 'string'\n      ? path\n          .replace(/\\[(\\d+)\\]/g, '.$1')\n          .split('.')\n          .filter(Boolean)\n      : [...path];\n\n  let result: unknown = obj;\n\n  for (const key of pathArray) {\n    if (result == null || (typeof result !== 'object' && typeof result !== 'function')) {\n      return defaultValue as T | D;\n    }\n    result = (result as Record<PropertyKey, unknown>)[key];\n  }\n\n  return result === undefined ? (defaultValue as T | D) : (result as T);\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,IACd,KACA,MACA,cACO;CACP,IAAI,OAAO,MACT,OAAO;CAIT,MAAM,YACJ,OAAO,SAAS,WACZ,KACG,QAAQ,cAAc,KAAK,CAAC,CAC5B,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,IACjB,CAAC,GAAG,IAAI;CAEd,IAAI,SAAkB;CAEtB,KAAK,MAAM,OAAO,WAAW;EAC3B,IAAI,UAAU,QAAS,OAAO,WAAW,YAAY,OAAO,WAAW,YACrE,OAAO;EAET,SAAU,OAAwC;CACpD;CAEA,OAAO,WAAW,KAAA,IAAa,eAA0B;AAC3D"}