]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/github-url-from-git/index.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / github-url-from-git / index.js
1 // convert git:// form url to github URL, e.g.,
2 // git://github.com/bcoe/foo.git
3 // https://github.com/bcoe/foo.
4 function githubUrlFromGit(url, opts){
5   try {
6     var m = re(opts).exec(url.replace(/\.git(#.*)?$/, ''));
7     var host = m[1];
8     var path = m[2];
9     return 'https://' + host + '/' + path;
10   } catch (err) {
11     // ignore
12   }
13 };
14
15 // generate the git:// parsing regex
16 // with options, e.g., the ability
17 // to specify multiple GHE domains.
18 function re(opts) {
19   opts = opts || {};
20   // whitelist of URLs that should be treated as GitHub repos.
21   var baseUrls = ['gist.github.com', 'github.com'].concat(opts.extraBaseUrls || []);
22   // build regex from whitelist.
23   return new RegExp(
24     /^(?:https?:\/\/|git:\/\/|git\+ssh:\/\/|git\+https:\/\/)?(?:[^@]+@)?/.source +
25     '(' + baseUrls.join('|') + ')' +
26     /[:\/]([^\/]+\/[^\/]+?|[0-9]+)$/.source
27   );
28 }
29
30 githubUrlFromGit.re = re();
31
32 module.exports = githubUrlFromGit;