import { stringify as stringifyParams } from 'query-string' ; interface Params { [ x ] : unknown ; } export function concatParams ( URL , params ? ) { return params ? `${ URL }?${ stringifyParams ( params ) }` . replace ( /\?$/ , '' ) : URL ; } export function combine ( baseURL , relativeURL ) { return `${ baseURL . replace ( /\/+$/ , '' ) }/${ relativeURL . replace ( /^\/+/ , '' ) }` ; } export function isAbsolute ( url ) { return /^([a-z][a-z\d+-.]*:)?\/\//i . test ( url ) ; } export function format ( baseUrl , relativeURL , params ? ) { if ( ! baseUrl || isAbsolute ( relativeURL ) ) { return concatParams ( relativeURL , params ) ; } return concatParams ( combine ( baseUrl , relativeURL ) , params ) ; }