interface QueryObject { [key: string]: string; } // Returns the query string as an object // when there are duplicate keys, the last key wins export function getQueryParams(): QueryObject { const searchParams = new URLSearchParams(document.location.search); const entries = searchParams.entries(); let result = {}; for (let entry of entries) { const [key, value] = entry; result[key] = value; } return result; } // Convert an object to a query string // does not handle nested objects export function toQueryString(queryObject) { const searchParams = new URLSearchParams(""); const newEntries = Object.entries(queryObject); for (let entry of newEntries) { const [key, value] = entry; if (!(typeof value === "undefined")) { searchParams.set(key, value.toString()); } } return searchParams.toString(); }