39 lines
904 B
JavaScript
39 lines
904 B
JavaScript
export const getURLParameters = (url) =>
|
|
(url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
|
|
(a, v) => (
|
|
(a[v.slice(0, v.indexOf("="))] = v.slice(v.indexOf("=") + 1)), a
|
|
),
|
|
{}
|
|
);
|
|
|
|
export const getQueryString = (variable) => {
|
|
let split = window.location.hash.split("?");
|
|
if (split.length <= 1) {
|
|
return null;
|
|
}
|
|
var query = split[1];
|
|
var vars = query.split("&");
|
|
for (var i = 0; i < vars.length; i++) {
|
|
var pair = vars[i].split("=");
|
|
if (pair[0] == variable) {
|
|
return pair[1];
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export const convertToUrlString = (data) => {
|
|
const _result = [];
|
|
for (const key in data) {
|
|
const value = data[key];
|
|
if (value.constructor === Array) {
|
|
value.forEach(function (_value) {
|
|
_result.push(key + "=" + _value);
|
|
});
|
|
} else {
|
|
_result.push(key + "=" + value);
|
|
}
|
|
}
|
|
return _result.join("&");
|
|
};
|