Last active
May 6, 2021 05:02
-
-
Save fergalhanley/8743cdda4beee24c37efc5eafe4a90e3 to your computer and use it in GitHub Desktop.
Typescript/JS function for parsing a URL and returning the query parameters as an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const parseQueryParameters = (url) => { | |
const parsed = {} | |
const matches = url.match("\\?([^#]+)") | |
if (matches && matches.length >= 2) { | |
const query = matches[1] | |
query.split('&').forEach((params) => { | |
const frag = params.split('=') | |
parsed[frag[0]] = frag[1] | |
}) | |
} | |
return parsed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment