lbry-desktop/ui/js/util/query_params.js

25 lines
550 B
JavaScript
Raw Normal View History

export function parseQueryParams(queryString) {
2017-06-06 17:19:12 -04:00
if (queryString === "") return {};
const parts = queryString.split("?").pop().split("&").map(function(p) {
return p.split("=");
});
2017-05-07 19:50:32 +07:00
const params = {};
parts.forEach(function(arr) {
params[arr[0]] = arr[1];
2017-06-06 17:19:12 -04:00
});
2017-05-07 19:50:32 +07:00
return params;
}
export function toQueryString(params) {
2017-06-06 17:19:12 -04:00
if (!params) return "";
2017-06-06 17:19:12 -04:00
const parts = [];
for (const key in params) {
if (params.hasOwnProperty(key) && params[key]) {
2017-06-06 17:19:12 -04:00
parts.push(key + "=" + params[key]);
}
}
2017-06-06 17:19:12 -04:00
return parts.join("&");
}