github-url-from-git
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,8 +1,9 @@ | ||
var re = /^(?:https?:\/\/|git:\/\/)?(?:[^@]+@)?(gist.github.com|github.com)[:\/]([^\/]+\/[^\/]+?|[0-9]+)$/ | ||
module.exports = function(url){ | ||
try { | ||
var m = /^.*?github\.com[:\/]([^\/]+)\/([^\/.]+)(?:\.git)?/.exec(url); | ||
var user = m[1]; | ||
var repo = m[2]; | ||
return 'https://github.com/' + user + '/' + repo; | ||
var m = re.exec(url.replace(/\.git$/, '')); | ||
var host = m[1]; | ||
var path = m[2]; | ||
return 'https://' + host + '/' + path; | ||
} catch (err) { | ||
@@ -9,0 +10,0 @@ // ignore |
{ | ||
"name": "github-url-from-git", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Parse a github git url and return the github repo url", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha test.js --reporter spec --require should" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": "", |
@@ -25,3 +25,18 @@ | ||
}) | ||
}); | ||
it('should return undefined on failure', function(){ | ||
var url = 'git://github.com/justgord/.git'; | ||
assert(null == parse(url)); | ||
}) | ||
it('should parse git@gist urls', function() { | ||
var url = 'git@gist.github.com:3135914.git'; | ||
parse(url).should.equal('https://gist.github.com/3135914') | ||
}) | ||
it('should parse https://gist urls', function() { | ||
var url = 'https://gist.github.com/3135914.git'; | ||
parse(url).should.equal('https://gist.github.com/3135914') | ||
}) | ||
}) | ||
``` |
10
test.js
@@ -30,2 +30,12 @@ | ||
}) | ||
it('should parse git@gist urls', function() { | ||
var url = 'git@gist.github.com:3135914.git'; | ||
parse(url).should.equal('https://gist.github.com/3135914') | ||
}) | ||
it('should parse https://gist urls', function() { | ||
var url = 'https://gist.github.com/3135914.git'; | ||
parse(url).should.equal('https://gist.github.com/3135914') | ||
}) | ||
}) |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
3565
7
43
1
42