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