Created
July 17, 2020 19:11
-
-
Save davelnewton/3ea481f7e2f22cc6612363f75669b2e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 function fromUrlQuery(str) { | |
if (!str) return {} | |
if (str[0] === '?') str = str.slice(1, str.length) | |
return str.split('&').reduce((acc, vars) => { | |
const [key, val] = vars.split('=').map(decodeURIComponent) | |
acc[key] = val | |
return acc | |
}, {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment