lbry-desktop/src/renderer/js/util/query_params.js

29 lines
574 B
JavaScript
Raw Normal View History

export function parseQueryParams(queryString) {
2017-06-06 23:19:12 +02:00
if (queryString === "") return {};
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;
}
export function toQueryString(params) {
2017-06-06 23:19:12 +02:00
if (!params) return "";
2017-06-06 23:19:12 +02:00
const parts = [];
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-06-06 23:19:12 +02:00
return parts.join("&");
}