mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-30 17:01:25 +00:00
28 lines
609 B
JavaScript
28 lines
609 B
JavaScript
export function parseQueryParams(queryString) {
|
|
if (queryString === '') return {};
|
|
const parts = queryString
|
|
.split('?')
|
|
.pop()
|
|
.split('&')
|
|
.map(p => p.split('='));
|
|
|
|
const params = {};
|
|
parts.forEach(array => {
|
|
const [first, second] = array;
|
|
params[first] = second;
|
|
});
|
|
return params;
|
|
}
|
|
|
|
export function toQueryString(params) {
|
|
if (!params) return '';
|
|
|
|
const parts = [];
|
|
Object.keys(params).forEach(key => {
|
|
if (Object.prototype.hasOwnProperty.call(params, key) && params[key]) {
|
|
parts.push(`${key}=${params[key]}`);
|
|
}
|
|
});
|
|
|
|
return parts.join('&');
|
|
}
|