Skip to content

Instantly share code, notes, and snippets.

@davelnewton
Created July 17, 2020 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davelnewton/3ea481f7e2f22cc6612363f75669b2e5 to your computer and use it in GitHub Desktop.
Save davelnewton/3ea481f7e2f22cc6612363f75669b2e5 to your computer and use it in GitHub Desktop.
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