export interface Parameters { [ id ] : string ; } export default class UrlParameterService { public getQueryParams ( qs ) { qs = qs . split ( "+" ) . join ( " " ) ; const params = { } ; let tokens ; const re = /[?&]?([^=]+)=([^&]*)/g ; while ( ( tokens = re . exec ( qs ) ) ) { params [ decodeURIComponent ( tokens [ 1 ] ) ] = decodeURIComponent ( tokens [ 2 ] ) ; } return params ; } public createVisualizationLinkForCurrentUrl ( href , params ) { const paramsStartPosition = href . indexOf ( "?" ) ; const hrefParamsPart = href . substr ( paramsStartPosition , href . length ) ; const hrefParams = this . getQueryParams ( hrefParamsPart ) ; if ( paramsStartPosition >= 0 ) { href = href . substr ( 0 , href . indexOf ( "?" ) ) ; } return href + this . createUrlParameterList ( hrefParams , params ) ; } private createUrlParameterList ( existingParameters , parameters ) { parameters = Object . assign ( existingParameters , parameters ) ; let result = "?" ; for ( const key in parameters ) { if ( parameters [ key ] ) { result += key + "=" + parameters [ key ] + "&" ; } } return result . substr ( 0 , result . length - 1 ) ; } }