{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TObjPath = string | readonly PropertyKey[];\n\nexport type TGetObjValueByPathArgs = Parameters<typeof getObjValueByPath>;\n\nexport type TGetObjValueByPathReturn = ReturnType<typeof getObjValueByPath>;\n\nconst getPathParts = (path: TObjPath): readonly PropertyKey[] => {\n  if (typeof path === \"string\") {\n    if (path.length === 0 || path.split(\".\").some((part) => part.length === 0)) {\n      throw new TypeError(\"getObjValueByPath: path must be a non-empty dot path\");\n    }\n    return path.split(\".\");\n  }\n  if (!Array.isArray(path) || path.length === 0) {\n    throw new TypeError(\"getObjValueByPath: path must be a non-empty string or key array\");\n  }\n  if (path.some((part) => ![ \"number\", \"string\", \"symbol\" ].includes(typeof part))) {\n    throw new TypeError(\"getObjValueByPath: path must contain property keys\");\n  }\n  return path;\n};\n\n/**\n * Reads a nested own property using a dot path or an array of property keys.\n * Returns the fallback when traversal fails or the resolved value is `undefined`.\n * @template TValue\n * @param {object} obj Source object or array\n * @param {TObjPath} path Dot path or property-key array\n * @param {TValue} [fallback] Value returned for a missing path\n * @returns {TValue|undefined} Resolved value or fallback\n * @throws {TypeError} getObjValueByPath: arguments are invalid\n * @example\n * const sellerName = getObjValueByPath<string>(product, \"seller.profile.name\", \"Unknown\");\n * @example\n * // Array paths support indexes, symbols, and keys that contain dots\n * const quantity = getObjValueByPath<number>(order, [ \"items\", 0, \"quantity\" ], 0);\n */\nexport const getObjValueByPath = <TValue = unknown>(\n  obj: object,\n  path: TObjPath,\n  fallback?: TValue\n): TValue | undefined => {\n  if ((typeof obj !== \"object\" && typeof obj !== \"function\") || obj === null) {\n    throw new TypeError(\"getObjValueByPath: obj must be an object\");\n  }\n  const parts = getPathParts(path);\n  let current: unknown = obj;\n\n  for (const part of parts) {\n    if (\n      current === null\n      || (typeof current !== \"object\" && typeof current !== \"function\")\n      || !Object.prototype.hasOwnProperty.call(current, part)\n    ) {\n      return fallback;\n    }\n    current = Reflect.get(current, part);\n  }\n\n  return current === undefined ? fallback : current as TValue;\n};\n"],"names":["getPathParts","path","length","split","some","part","TypeError","Array","isArray","includes","getObjValueByPath","obj","fallback","parts","current","Object","prototype","hasOwnProperty","call","Reflect","get","undefined"],"mappings":"yDAMA,MAAMA,aAAgBC,OACpB,UAAWA,OAAS,SAAU,CAC5B,GAAIA,KAAKC,SAAW,GAAKD,KAAKE,MAAM,KAAKC,KAAMC,MAASA,KAAKH,SAAW,GACtE,MAAM,IAAII,UAAU,wDAEtB,OAAOL,KAAKE,MAAM,IACpB,CACA,IAAKI,MAAMC,QAAQP,OAASA,KAAKC,SAAW,EAC1C,MAAM,IAAII,UAAU,mEAEtB,GAAIL,KAAKG,KAAMC,OAAU,CAAE,SAAU,SAAU,UAAWI,gBAAgBJ,OACxE,MAAM,IAAIC,UAAU,sDAEtB,OAAOL,MAkBF,MAAMS,kBAAoB,CAC/BC,IACAV,KACAW,YAEA,UAAYD,MAAQ,iBAAmBA,MAAQ,YAAeA,MAAQ,KACpE,MAAM,IAAIL,UAAU,4CAEtB,MAAMO,MAAQb,aAAaC,MAC3B,IAAIa,QAAmBH,IAEvB,IAAK,MAAMN,QAAQQ,MAAO,CACxB,GACEC,UAAY,aACDA,UAAY,iBAAmBA,UAAY,aAClDC,OAAOC,UAAUC,eAAeC,KAAKJ,QAAST,MAElD,OAAOO,SAETE,QAAUK,QAAQC,IAAIN,QAAST,KACjC,CAEA,OAAOS,eAAYO,EAAYT,SAAWE"}