Skip to content

Instantly share code, notes, and snippets.

@admcfajn
Last active June 30, 2020 07:10
Show Gist options
  • Select an option

  • Save admcfajn/2ed5d46b8ee96cbdd0b8d16f1be2f6f0 to your computer and use it in GitHub Desktop.

Select an option

Save admcfajn/2ed5d46b8ee96cbdd0b8d16f1be2f6f0 to your computer and use it in GitHub Desktop.
Build URL Object
/*
* Build URL Object
* Returns dest: current url-base, sub_params_out: json-object with get-params as names & arrays built from csv-string
**/
function build_url_object(){
let
dest = window.location.origin + window.location.pathname,
params = window.location.search.replace( '?', '' ),
sub_params = null,
sub_params_out = {};
if ( params.length ) {
sub_params = params.split( '&' );
}
if ( sub_params ) {
for ( let i in sub_params ) {
let item = sub_params[ i ].split( '=' );
sub_params_out[ item[ 0 ] ] = item[ 1 ].split( ',' );
}
}
return { 'dest': dest, 'sub_params_out': sub_params_out };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment