port.js 524 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. function parsePort(urlObj, options)
  3. {
  4. var defaultPort = -1;
  5. for (var i in options.defaultPorts)
  6. {
  7. if ( i===urlObj.scheme && options.defaultPorts.hasOwnProperty(i) )
  8. {
  9. defaultPort = options.defaultPorts[i];
  10. break;
  11. }
  12. }
  13. if (defaultPort > -1)
  14. {
  15. // Force same type as urlObj.port
  16. defaultPort = defaultPort.toString();
  17. if (urlObj.port === null)
  18. {
  19. urlObj.port = defaultPort;
  20. }
  21. urlObj.extra.portIsDefault = (urlObj.port === defaultPort);
  22. }
  23. }
  24. module.exports = parsePort;