function normalizeUrl (url, base = undefined) {
  try {
    let {protocol, hostname, port, pathname, search, hash} = new URL(url, base)
    return `${protocol}//${hostname}${(port ? `:${port}` : '')}${pathname || '/'}${search}${hash}`
  } catch {
    return url
  }
}
@param {String} url
@param {String} [base]
@returns {String}