2017-05-23 10:46:52 +02:00
|
|
|
export function parseQueryParams(queryString) {
|
2017-06-06 23:19:12 +02:00
|
|
|
if (queryString === "") return {};
|
2017-11-24 15:31:05 +01:00
|
|
|
const parts = queryString
|
|
|
|
.split("?")
|
|
|
|
.pop()
|
|
|
|
.split("&")
|
|
|
|
.map(function(p) {
|
|
|
|
return p.split("=");
|
|
|
|
});
|
2017-05-07 14:50:32 +02:00
|
|
|
|
|
|
|
const params = {};
|
|
|
|
parts.forEach(function(arr) {
|
|
|
|
params[arr[0]] = arr[1];
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-07 14:50:32 +02:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2017-05-23 10:46:52 +02:00
|
|
|
export function toQueryString(params) {
|
2017-06-06 23:19:12 +02:00
|
|
|
if (!params) return "";
|
2017-05-23 10:46:52 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
const parts = [];
|
2017-05-23 10:46:52 +02:00
|
|
|
for (const key in params) {
|
|
|
|
if (params.hasOwnProperty(key) && params[key]) {
|
2017-06-06 23:19:12 +02:00
|
|
|
parts.push(key + "=" + params[key]);
|
2017-05-23 10:46:52 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
return parts.join("&");
|
2017-05-23 10:46:52 +02:00
|
|
|
}
|