Enhance readQueryVariable to support boolean, numeric and string values

This commit is contained in:
Mauro I. Dominguez 2025-06-02 09:28:54 -03:00
parent 4cb5aa45ae
commit d3a1bd8805
1 changed files with 16 additions and 1 deletions

View File

@ -117,7 +117,22 @@
if (match) { if (match) {
// We have to decode the URL since want the cleartext value // We have to decode the URL since want the cleartext value
return decodeURIComponent(match[1]); const value = decodeURIComponent(match[1]);
if (value.toLowerCase() === 'false' || value === '0') {
return false;
}
if (value.toLowerCase() === 'true' || value === '1') {
return true;
}
// Check for integer
if (/^-?\d+$/.test(value)) {
return parseInt(value, 10);
}
// Check for float
if (/^-?\d*\.\d+$/.test(value)) {
return parseFloat(value);
}
return value;
} }
return defaultValue; return defaultValue;