1 var url = require('url')
3 module.exports = function normalize (u) {
4 var parsed = url.parse(u)
5 // If parsing actually alters the URL, it is almost certainly an
6 // scp-style URL, or an invalid one.
7 var altered = u !== url.format(parsed)
10 // if the path is like ssh://foo:22/some/path then it works, but
11 // it needs the ssh://
12 // If the path is like ssh://foo:some/path then it works, but
13 // only if you remove the ssh://
14 if (parsed.protocol) {
15 parsed.protocol = parsed.protocol.replace(/^git\+/, '')
18 // figure out what we should check out.
19 var checkout = parsed.hash && parsed.hash.substr(1) || 'master'
24 if (u.match(/^git\+https?/) && parsed.pathname.match(/\/?:[^0-9]/)) {
25 returnedUrl = u.replace(/^git\+(.*:[^:]+):(.*)/, '$1/$2')
26 } else if (u.match(/^git\+file/)) {
27 returnedUrl = u.replace(/^git\+/, '')
29 returnedUrl = u.replace(/^(?:git\+)?ssh:\/\//, '')
31 returnedUrl = returnedUrl.replace(/#[^#]*$/, '')
33 returnedUrl = url.format(parsed)