index.js 553 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. // Copied from https://github.com/nodejs/node/blob/master/lib/internal/url.js
  3. function urlToOptions(url) {
  4. var options = {
  5. protocol: url.protocol,
  6. hostname: url.hostname,
  7. hash: url.hash,
  8. search: url.search,
  9. pathname: url.pathname,
  10. path: `${url.pathname}${url.search}`,
  11. href: url.href
  12. };
  13. if (url.port !== '') {
  14. options.port = Number(url.port);
  15. }
  16. if (url.username || url.password) {
  17. options.auth = `${url.username}:${url.password}`;
  18. }
  19. return options;
  20. }
  21. module.exports = urlToOptions;