improve parseQueryString function

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-12 22:13:54 +02:00
parent f20cca6e15
commit 1dcd501b13

View File

@@ -4,7 +4,8 @@ export const parseQueryString = (obj: Record<string, any>): any => {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => {
if (typeof v === 'object') return [k, parseQueryString(v)];
if (!isNaN(parseFloat(v))) return [k, parseFloat(v)];
if (/^-?[0-9]+(\.[0-9]+)?$/i.test(v) && !isNaN(parseFloat(v)))
return [k, parseFloat(v)];
if (v === 'true') return [k, true];
if (v === 'false') return [k, false];
if (typeof v === 'string') {