{"version":3,"file":"7ZSJCcLQ.js","sources":["../../../../src/composables/useFilters.ts"],"sourcesContent":["export const useFilters = () => {\n const parseFilters = (filters: any) => {\n const form = jsonToFormData(filters)\n return formDataToQueryString(form);\n }\n const jsonToQueryString = (obj: Record, prefix = ''): string => {\n return Object.entries(obj)\n .map(([key, value]) => {\n const newKey = prefix ? `${prefix}[${key}]` : key;\n if (typeof value === 'object' && !Array.isArray(value)) {\n return jsonToQueryString(value, newKey);\n } else if (Array.isArray(value)) {\n return value\n .map((item, index) => jsonToQueryString(item, `${newKey}[${index}]`))\n .join(\"&\");\n } else {\n return `${encodeURIComponent(newKey)}=${encodeURIComponent(value)}`;\n }\n })\n .join(\"&\");\n }\n const jsonToFormData = (data: any, formData: FormData = new FormData(), parentKey: string = ''): FormData => {\n // Recorremos cada key del objeto o arreglo\n for (const key in data) {\n if (!data.hasOwnProperty(key)) continue;\n\n const value = data[key];\n // Construimos la clave completa (ej: user[contact][email])\n const formKey = parentKey\n ? `${parentKey}[${key}]`\n : key;\n\n // Si el valor es un objeto y no es nulo ni array, hacemos recursión\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n jsonToFormData(value, formData, formKey);\n\n // Si el valor es un array, iteramos sus elementos\n } else if (Array.isArray(value)) {\n value.forEach((item, index) => {\n const arrayKey = `${formKey}[${index}]`;\n if (typeof item === 'object' && item !== null) {\n jsonToFormData(item, formData, arrayKey);\n } else {\n formData.append(arrayKey, String(item));\n }\n });\n\n // De lo contrario, lo consideramos un valor plano (number, string, boolean...)\n } else {\n formData.append(formKey, String(value));\n }\n }\n\n return formData;\n }\n const formDataToQueryString = (formData: FormData): string => {\n const queryParams = new URLSearchParams();\n\n for (const [key, value] of formData.entries()) {\n // Convertimos el valor a string (por si es un Blob, File u otro tipo)\n queryParams.append(key, String(value));\n }\n\n return queryParams.toString();\n }\n const parseQueryStructured = (obj: any): any => {\n const result: any[] = [];\n\n for (const [key, rawValue] of Object.entries(obj)) {\n // \"0[type]\" => [\"0\",\"type\"]\n // \"1[value]\" => [\"1\",\"value\"]\n const parts = key.split(/\\[/).map(part => part.replace(/\\]/g, ''));\n\n let current: any = result;\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n const isLast = i === parts.length - 1;\n\n if (isLast) {\n // Asignamos el valor tal cual (si es array, objeto, string, etc.)\n current[part] = rawValue;\n } else {\n // Miramos si la siguiente parte es un índice numérico => creamos array\n const nextPart = parts[i + 1];\n const isNextPartNumber = !isNaN(Number(nextPart));\n\n // Si no existe, creamos la estructura necesaria\n if (!(part in current)) {\n current[part] = isNextPartNumber ? [] : {};\n }\n\n // Bajamos un nivel\n current = current[part];\n }\n }\n }\n\n return result;\n };\n const parseToObject = (input: any) => {\n const output = {};\n\n Object.keys(input).forEach(key => {\n // Extraer el índice y la propiedad usando RegEx\n const match = key.match(/filters\\[(\\d+)\\]\\[(\\w+)\\]/);\n\n if (match) {\n const index = match[1];\n const prop = match[2];\n\n if (!output[index]) {\n output[index] = {};\n }\n\n output[index][prop] = input[key];\n }\n });\n\n // Convertir el objeto de salida en un arreglo\n return Object.values(output);\n }\n\n\n return {\n parseFilters,\n jsonToQueryString,\n parseQueryStructured,\n parseToObject\n }\n}\n\n"],"names":["useFilters","parseFilters","filters","form","jsonToFormData","formDataToQueryString","jsonToQueryString","obj","prefix","key","value","newKey","item","index","data","formData","parentKey","formKey","arrayKey","queryParams","result","rawValue","parts","part","current","i","nextPart","isNextPartNumber","input","output","match","prop"],"mappings":"AAAO,MAAMA,EAAa,IAAM,CACtB,MAAAC,EAAgBC,GAAiB,CAC7B,MAAAC,EAAOC,EAAeF,CAAO,EACnC,OAAOG,EAAsBF,CAAI,CAAA,EAE/BG,EAAoB,CAACC,EAA0BC,EAAS,KACnD,OAAO,QAAQD,CAAG,EACpB,IAAI,CAAC,CAACE,EAAKC,CAAK,IAAM,CACnB,MAAMC,EAASH,EAAS,GAAGA,CAAM,IAAIC,CAAG,IAAMA,EAC9C,OAAI,OAAOC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