import url from 'url' ; export function getPath ( urlParam ) { if ( typeof window === 'undefined' || window . navigator . userAgent . indexOf ( 'Node.js' ) >= 0 ) { const path = url . parse ( urlParam ) . pathname ; return path ? path : '/' ; } return browserGetPath ( urlParam ) ; } let link ; function browserGetPath ( urlParam ) { if ( ! link ) { link = document . createElement ( 'a' ) ; } link . href = urlParam ; let path = link . pathname ; if ( path [ 0 ] !== '/' ) { path = `/${ path }` ; } return path ; }