]> gerrit.simantics Code Review - simantics/district.git/blobdiff - 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
diff --git a/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/github-url-from-git/index.js b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/github-url-from-git/index.js
new file mode 100644 (file)
index 0000000..44872e8
--- /dev/null
@@ -0,0 +1,32 @@
+// convert git:// form url to github URL, e.g.,
+// git://github.com/bcoe/foo.git
+// https://github.com/bcoe/foo.
+function githubUrlFromGit(url, opts){
+  try {
+    var m = re(opts).exec(url.replace(/\.git(#.*)?$/, ''));
+    var host = m[1];
+    var path = m[2];
+    return 'https://' + host + '/' + path;
+  } catch (err) {
+    // ignore
+  }
+};
+
+// generate the git:// parsing regex
+// with options, e.g., the ability
+// to specify multiple GHE domains.
+function re(opts) {
+  opts = opts || {};
+  // whitelist of URLs that should be treated as GitHub repos.
+  var baseUrls = ['gist.github.com', 'github.com'].concat(opts.extraBaseUrls || []);
+  // build regex from whitelist.
+  return new RegExp(
+    /^(?:https?:\/\/|git:\/\/|git\+ssh:\/\/|git\+https:\/\/)?(?:[^@]+@)?/.source +
+    '(' + baseUrls.join('|') + ')' +
+    /[:\/]([^\/]+\/[^\/]+?|[0-9]+)$/.source
+  );
+}
+
+githubUrlFromGit.re = re();
+
+module.exports = githubUrlFromGit;