import { HashMap } from './api_types' ; export const toQueryString = ( obj ) : string => { const parts = Object . keys ( obj ) . reduce ( ( accumulator , key ) : ReadonlyArray < string > => [ ... accumulator , `${ encodeURIComponent ( key ) }=${ encodeURIComponent ( obj [ key ] ) }` , ] , [ ] ) ; return parts . join ( '&' ) ; } ; const urlParamRegex = /{[^}]+}/ ; export const solveURLParams = ( url , params = { } ) : string => { if ( Object . keys ( params ) . length === 0 ) { if ( url . match ( urlParamRegex ) !== null ) { throw new Error ( 'URL is not completely solved' ) ; } return url ; } const solvedURL = Object . keys ( params ) . reduce ( ( accumulator , key ) : string => accumulator . replace ( `{${ key }}` , params [ key ] ) , url ) ; if ( solvedURL . match ( urlParamRegex ) !== null ) { throw new Error ( 'URL is not completely solved' ) ; } return encodeURI ( solvedURL ) ; } ;