1 module.exports = getUrl
3 function getUrl (r, forBrowser) {
5 // Regex taken from https://github.com/npm/npm-package-arg/commit/01dce583c64afae07b66a2a8a6033aeba871c3cd
6 // Note: This does not fully test the git ref format.
7 // See https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
9 // The only way to do this properly would be to shell out to
10 // git-check-ref-format, and as this is a fast sync function,
11 // we don't want to do that. Just let git fail if it turns
12 // out that the commit-ish is invalid.
13 // GH usernames cannot start with . or -
14 if (/^[^@%\/\s\.-][^:@%\/\s]*\/[^@\s\/%]+(?:#.*)?$/.test(r)) {
16 r = r.replace("#", "/tree/")
17 return "https://github.com/" + r