Last active
February 5, 2017 03:39
-
-
Save joshcanhelp/20ce08247073e1c443b37af343d992f1 to your computer and use it in GitHub Desktop.
Get the various parameters from a URL piece, hash or query
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
| /** | |
| * Get the various parameters from a URL piece, hash or query | |
| * | |
| * @param params | |
| * | |
| * @returns {{}} | |
| */ | |
| function parseUrlParams( params ) { | |
| 'use strict'; | |
| // Nothing to parse | |
| if ( params.indexOf( '&' ) < 0 ) { | |
| return {}; | |
| } | |
| var pieces = {}; | |
| // Normalize param string in case it was passed in with prepended char | |
| params = params.replace( '?', '' ); | |
| params = params.replace( '#', '' ); | |
| params.split( '&' ).forEach( function ( el ) { | |
| pieces[ el.split( '=' )[ 0 ] ] = el.split( '=' )[ 1 ]; | |
| } ); | |
| return pieces; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment