lbry-redux/src/util/query_params.js

29 lines
609 B
JavaScript
Raw Normal View History

2018-04-05 03:57:29 +01:00
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('&');
}