github-url-to-object
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -0,3 +1,8 @@ | ||
var isUrl = require('is-url') | ||
module.exports = function(url) { | ||
// bail if given a non-github URL | ||
if (isUrl(url) && !url.match(/github\.com/)) return null | ||
var re = /^(?:https?:\/\/|git:\/\/)?(?:[^@]+@)?(gist.github.com|github.com)[:\/]([^\/]+\/[^\/]+?|[0-9]+)$/ | ||
@@ -4,0 +9,0 @@ var match = re.exec(url.replace(/\.git$/, '')); |
{ | ||
"name": "github-url-to-object", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Extract username and repo name from various flavors of GitHub URLs", | ||
@@ -22,3 +22,6 @@ "main": "index.js", | ||
"url": "https://github.com/zeke/github-url-to-object/issues" | ||
}, | ||
"dependencies": { | ||
"is-url": "^1.0.0" | ||
} | ||
} |
@@ -1,43 +0,54 @@ | ||
var mocha = require("mocha"); | ||
var assert = require("assert"); | ||
var gh = require("../index"); | ||
var mocha = require("mocha") | ||
var assert = require("assert") | ||
var gh = require("../index") | ||
describe("github-url-to-object", function() { | ||
it("extracts username and repo from github URL", function() { | ||
var obj = gh("https://github.com/heroku/heroku-buildpack-nodejs.git"); | ||
assert.equal(obj.user, 'heroku'); | ||
assert.equal(obj.repo, 'heroku-buildpack-nodejs'); | ||
}); | ||
var obj = gh("https://github.com/heroku/heroku-buildpack-nodejs.git") | ||
assert.equal(obj.user, 'heroku') | ||
assert.equal(obj.repo, 'heroku-buildpack-nodejs') | ||
}) | ||
it("handles URLs without .git at the end", function() { | ||
var obj = gh("https://github.com/zeke/outlet"); | ||
assert.equal(obj.user, 'zeke'); | ||
assert.equal(obj.repo, 'outlet'); | ||
}); | ||
var obj = gh("https://github.com/zeke/outlet") | ||
assert.equal(obj.user, 'zeke') | ||
assert.equal(obj.repo, 'outlet') | ||
}) | ||
it("handles http URLs", function() { | ||
var obj = gh("http://github.com/zeke/outlet.git"); | ||
assert.equal(obj.user, 'zeke'); | ||
assert.equal(obj.repo, 'outlet'); | ||
}); | ||
var obj = gh("http://github.com/zeke/outlet.git") | ||
assert.equal(obj.user, 'zeke') | ||
assert.equal(obj.repo, 'outlet') | ||
}) | ||
it("handles https URLs", function() { | ||
var obj = gh("https://github.com/zeke/outlet.git"); | ||
assert.equal(obj.user, 'zeke'); | ||
assert.equal(obj.repo, 'outlet'); | ||
}); | ||
var obj = gh("https://github.com/zeke/outlet.git") | ||
assert.equal(obj.user, 'zeke') | ||
assert.equal(obj.repo, 'outlet') | ||
}) | ||
it("handles git URLs", function() { | ||
var obj = gh("git://github.com/foo/bar.git"); | ||
assert.equal(obj.user, 'foo'); | ||
assert.equal(obj.repo, 'bar'); | ||
}); | ||
var obj = gh("git://github.com/foo/bar.git") | ||
assert.equal(obj.user, 'foo') | ||
assert.equal(obj.repo, 'bar') | ||
}) | ||
it("handles shorthand user/repo paths", function() { | ||
var obj = gh("foo/bar"); | ||
assert.equal(obj.user, 'foo'); | ||
assert.equal(obj.repo, 'bar'); | ||
}); | ||
var obj = gh("foo/bar") | ||
assert.equal(obj.user, 'foo') | ||
assert.equal(obj.repo, 'bar') | ||
}) | ||
it("handles git@ URLs", function() { | ||
var obj = gh("git@github.com:heroku/heroku-flags.git"); | ||
assert.equal(obj.user, 'heroku'); | ||
assert.equal(obj.repo, 'heroku-flags'); | ||
}); | ||
var obj = gh("git@github.com:heroku/heroku-flags.git") | ||
assert.equal(obj.user, 'heroku') | ||
assert.equal(obj.repo, 'heroku-flags') | ||
}) | ||
}); | ||
it("returns null for invalid URLs", function() { | ||
var obj = gh("https://bitbucket.com/other/thing") | ||
assert.equal(obj, null) | ||
}) | ||
}) |
3144
57
1
+ Addedis-url@^1.0.0
+ Addedis-url@1.2.4(transitive)