format.mjs 485 B

123456789101112131415161718192021
  1. export default function format (url) {
  2. let result = ''
  3. result += url.protocol || ''
  4. result += url.slashes ? '//' : ''
  5. result += url.auth ? url.auth + '@' : ''
  6. if (url.hostname && url.hostname.indexOf(':') !== -1) {
  7. // ipv6 address
  8. result += '[' + url.hostname + ']'
  9. } else {
  10. result += url.hostname || ''
  11. }
  12. result += url.port ? ':' + url.port : ''
  13. result += url.pathname || ''
  14. result += url.search || ''
  15. result += url.hash || ''
  16. return result
  17. };