format.js 514 B

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