10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-04 21:24:00 +01:00
QUESTDB_website/static/scripts/parseQueryStringToDictionary.js

32 lines
805 B
JavaScript
Raw Normal View History

function parseQueryStringToDictionary(queryString=window.location.search) {
var dictionary = {};
// remove the '?' from the beginning of the
// if it exists
if (queryString.indexOf('?') === 0) {
queryString = queryString.substr(1);
}
// Step 1: separate out each key/value pair
var parts = queryString.split('&');
for (var i = 0; i < parts.length; i++) {
var p = parts[i];
// Step 2: Split Key/Value pair
var keyValuePair = p.split('=');
// Step 3: Add Key/Value pair to Dictionary object
var key = keyValuePair[0];
var value = keyValuePair[1];
// decode URI encoded string
value = decodeURIComponent(value);
value = value.replace(/\+/g, ' ');
dictionary[key] = value;
}
// Step 4: Return Dictionary Object
return dictionary;
}