@ou-imdt/utils
Version:
Utility library for interactive media development
17 lines (15 loc) • 584 B
JavaScript
/**
* Retrieves URL parameters from the current window's URL and parses them into an object.
* @returns {Object} An object containing the URL parameters as key-value pairs. Boolean strings are parsed to boolean values.
*/
export default function getUrlParams() {
const url = new URL(window.location);
const urlParams = new URLSearchParams(url.search);
const params = Object.fromEntries(urlParams.entries());
Object.keys(params).forEach(key => {
if (['true', 'false'].includes(params[key])) {
params[key] = JSON.parse(params[key]);
}
});
return params;
}