import Hash from "../Hash" ; export type buildUrlOptions = { url ? : string ; queryParams ? : string | Hash < any > ; } ; export function buildUrl ( options , defaultUrl = "" ) { let url = ( options . url || defaultUrl ) . toString ( ) ; if ( url . length ) url = "/" + url ; if ( options . queryParams ) { url += "?" + buildEncodedQueryParams ( options . queryParams ) ; } return url ; } export function buildEncodedQueryParams ( queryParams ) { if ( typeof queryParams === "string" ) { return queryParams ; } return Object . keys ( queryParams ) . map ( key => `${ encodeURIComponent ( key ) }=${ encodeURIComponent ( queryParams [ key ] ) }` ) . join ( "&" ) ; } export function trailUrl ( url ) { return url . endsWith ( "/" ) ? url : url + "/" ; }