Skip to content

Instantly share code, notes, and snippets.

@alexsasharegan
Last active April 23, 2017 02:19
Show Gist options
  • Select an option

  • Save alexsasharegan/94bc7a7cdf811fcf1979f56fad793a7f to your computer and use it in GitHub Desktop.

Select an option

Save alexsasharegan/94bc7a7cdf811fcf1979f56fad793a7f to your computer and use it in GitHub Desktop.
Glorious usage of ES2015 to parse uri-encoded strings to plain javascript objects.
function decodeQueryStringToObj( qStr ) {
return Object.assign.apply( null, qStr.split( '&' ).map( pair => {
const [ key, val ] = pair.split( '=' ).map( decodeURIComponent )
return { [key]: val }
} ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment