{"version":3,"file":"get-nested-value.cjs","names":[],"sources":["../../src/utils/get-nested-value.ts"],"sourcesContent":["/**\n * Helper util to return a value from a certain path of the object.\n * Path is specified as either:\n * - a string of properties, separated by dots, for example: \"x.y\".\n * - an array of properties, for example `[ 'x', 'y' ]`.\n * You can also specify a default value in case the result is nullish.\n *\n * @param object       Input object.\n * @param path         Path to the object property.\n * @param defaultValue Default value if the value at the specified path is undefined.\n * @return Value of the object property at the specified path.\n */\nexport default function getNestedValue(\n\tobject: unknown,\n\tpath: string | Array< string | number >,\n\tdefaultValue?: unknown\n): unknown {\n\tif (\n\t\t! object ||\n\t\ttypeof object !== 'object' ||\n\t\t( typeof path !== 'string' && ! Array.isArray( path ) )\n\t) {\n\t\treturn object;\n\t}\n\tconst normalizedPath = Array.isArray( path ) ? path : path.split( '.' );\n\tlet value: unknown = object;\n\tnormalizedPath.forEach( ( fieldName ) => {\n\t\t// Reads through whatever value the path reaches, as `?.` allows.\n\t\tvalue = ( value as Record< string | number, unknown > )?.[ fieldName ];\n\t} );\n\treturn value !== undefined ? value : defaultValue;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAYA,SAAwB,eACvB,QACA,MACA,cACU;CACV,IACC,CAAE,UACF,OAAO,WAAW,YAChB,OAAO,SAAS,YAAY,CAAE,MAAM,QAAS,IAAK,GAEpD,OAAO;CAER,MAAM,iBAAiB,MAAM,QAAS,IAAK,IAAI,OAAO,KAAK,MAAO,GAAI;CACtE,IAAI,QAAiB;CACrB,eAAe,SAAW,cAAe;EAExC,QAAU,QAAiD;CAC5D,CAAE;CACF,OAAO,UAAU,KAAA,IAAY,QAAQ;AACtC"}