{"version":3,"sources":["../src/object/getByPath.ts"],"names":["getByPath","obj","path","options","defaultValue","delimiter","matched","keys","current","parent","indexOrKey","key","index"],"mappings":";;;;AAUO,SAASA,CAA+BC,CAAAA,CAAAA,CAAQC,CAAcC,CAAAA,CAAAA,CAA4B,CAC7F,GAAM,CAAE,YAAAC,CAAAA,CAAAA,CAAc,SAAAC,CAAAA,CAAAA,CAAU,OAAAC,CAAAA,CAAQ,EAAI,MAAO,CAAA,MAAA,CAAO,CACtD,SAAA,CAAY,GAChB,CAAA,CAAEH,CAAO,CAAA,CAET,GAAI,CAACF,CAAAA,EAAO,OAAOC,CAAAA,EAAS,QACxB,CAAA,OAAOE,CAEX,CAAA,GAAG,CAACF,CAAM,CAAA,OAAOD,CAEjB,CAAA,IAAMM,CAAOL,CAAAA,CAAAA,CAAK,KAAMG,CAAAA,CAAS,EAC7BG,CAAeP,CAAAA,CAAAA,CACfQ,CACAC,CAAAA,CAAAA,CACJ,GAAG,CACC,IAAWC,IAAAA,CAAAA,IAAOJ,EACd,GAAIC,CAAAA,YAAmB,GAAOA,EAAAA,CAAAA,YAAmB,OAAS,CAAA,CACtD,GAAG,CAACA,EAAQ,GAAIG,CAAAA,CAAU,CACtB,CAAA,OAAOP,EAEXK,CAAUD,CAAAA,CAAAA,CACVE,CAAaC,CAAAA,CAAAA,CACbH,EAAUA,CAAQ,CAAA,GAAA,CAAIG,CAAU,EACpC,CAAWH,KAAAA,GAAAA,CAAAA,YAAmB,GAAM,CAAA,CAChC,IAAMI,CAAQ,CAAA,QAAA,CAASD,CAAK,CAAA,EAAE,CAC9B,CAAA,GAAGC,CAAOJ,EAAAA,CAAAA,CAAQ,KAAM,OAAOJ,CAAAA,CAC/BK,CAAUD,CAAAA,CAAAA,CACVE,CAAaE,CAAAA,CAAAA,CACbJ,CAAU,CAAA,CAAC,GAAGA,CAAO,CAAA,CAAEI,CAAK,EAChC,SAAWJ,CAAW,EAAA,OAAOA,CAAY,EAAA,QAAA,EAAYG,KAAOH,CACxDC,CAAAA,CAAAA,CAAUD,CACVE,CAAAA,CAAAA,CAAa,KAAM,CAAA,OAAA,CAAQF,CAAO,CAAA,CAAI,SAASG,CAAG,CAAA,CAAIA,CACtDH,CAAAA,CAAAA,CAAUA,CAAQG,CAAAA,CAAG,CAErB,CAAA,KAAA,OAAOP,CAGnB,CAAM,KAAA,CACF,OAAOA,CACX,CACA,OAAG,OAAOE,CAAAA,EAAW,YACjBA,CAAQ,CAAA,CAAE,KAAME,CAAAA,CAAAA,CAAS,OAAAC,CAAQ,CAAA,UAAA,CAAAC,CAAW,CAAC,EAE1CF,CACX","file":"chunk-W3M3ZELD.mjs","sourcesContent":["export interface GetByPathArgs {\n    defaultValue?: any; // 默认值\n    delimiter?: string; // 路径分隔符，默认为 '.',\n    matched?: ({ value, parent, indexOrKey }: {\n        value?     : any;\n        parent?    : object | any[];\n        indexOrKey?:  string | symbol | number;\n    }) => void;\n}\n\nexport function getByPath<R = any, T = object>(obj: T, path: string, options?: GetByPathArgs): R {\n    const { defaultValue, delimiter,matched } = Object.assign({\n        delimiter : '.'\n    },options)\n\n    if (!obj || typeof path !== 'string') {\n        return defaultValue as R;\n    }\n    if(!path) return obj as R    \n\n    const keys = path.split(delimiter);\n    let current: any = obj;\n    let parent: any \n    let indexOrKey:any\n    try{\n        for (const key of keys) {\n            if (current instanceof Map || current instanceof WeakMap) {\n                if(!current.has(key as any)) {\n                    return defaultValue as R\n                }\n                parent =  current                \n                indexOrKey = key\n                current = current.get(key as any);\n            } else if (current instanceof Set)  {\n                const index = parseInt(key, 10)\n                if(index>=current.size) return defaultValue as R\n                parent =  current\n                indexOrKey = index\n                current = [...current][index];\n            } else if (current && typeof current === 'object' && key in current) {\n                parent =  current\n                indexOrKey = Array.isArray(current) ? parseInt(key) : key\n                current = current[key];\n            } else {\n                return defaultValue as R;\n            }\n        }\n    }catch{\n        return defaultValue as R\n    }   \n    if(typeof(matched)===\"function\"){\n        matched({ value:current, parent, indexOrKey })\n    }\n    return current as R\n}"]}