git-url-parse
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -9,3 +9,3 @@ # :eight_spoked_asterisk: :stars: :sparkles: :dizzy: :star2: :star2: :sparkles: :dizzy: :star2: :star2: Contributing :star: :star2: :dizzy: :sparkles: :star: :star2: :dizzy: :sparkles: :stars: :eight_spoked_asterisk: | ||
## Discuss the changes before doing them | ||
- First of all, open an issue in the repository, using the [bug tracker][1], | ||
- First of all, open an issue in the repository, using the [bug tracker][1] | ||
describing the contribution you'd like to make, the bug you found or any | ||
@@ -61,2 +61,3 @@ other ideas you have. This will help us to get you started on the right | ||
[1]: https://github.com/IonicaBizau/node-git-url-parse/issues | ||
[2]: https://github.com/IonicaBizau/code-style |
@@ -5,21 +5,41 @@ // Dependencies | ||
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git")); | ||
// => { protocol: 'ssh' | ||
// , source: 'github.com' | ||
// , owner: 'IonicaBizau' | ||
// , name: 'node-git-url-parse' | ||
// , _: 'git@github.com:IonicaBizau/node-git-url-parse.git' | ||
// , toString: [Function] } | ||
// => { | ||
// protocols: [] | ||
// , port: null | ||
// , resource: "github.com" | ||
// , user: "git" | ||
// , pathname: "/IonicaBizau/node-git-url-parse.git" | ||
// , hash: "" | ||
// , search: "" | ||
// , href: "git@github.com:IonicaBizau/node-git-url-parse.git" | ||
// , token: "" | ||
// , protocol: "ssh" | ||
// , toString: [Function] | ||
// , source: "github.com" | ||
// , name: "node-git-url-parse" | ||
// , owner: "IonicaBizau" | ||
// } { | ||
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git")); | ||
// => { protocol: 'https' | ||
// , source: 'github.com' | ||
// , owner: 'IonicaBizau' | ||
// , name: 'node-git-url-parse' | ||
// , _: 'https://github.com/IonicaBizau/node-git-url-parse.git' | ||
// , toString: [Function] } | ||
// => { | ||
// protocols: ["https"] | ||
// , port: null | ||
// , resource: "github.com" | ||
// , user: "" | ||
// , pathname: "/IonicaBizau/node-git-url-parse.git" | ||
// , hash: "" | ||
// , search: "" | ||
// , href: "https://github.com/IonicaBizau/node-git-url-parse.git" | ||
// , token: "" | ||
// , protocol: "https" | ||
// , toString: [Function] | ||
// , source: "github.com" | ||
// , name: "node-git-url-parse" | ||
// , owner: "IonicaBizau" | ||
// } | ||
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git").toString("ssh")); | ||
// => 'git@github.com:IonicaBizau/node-git-url-parse.git.git' | ||
// => "git@github.com:IonicaBizau/node-git-url-parse.git" | ||
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git").toString("https")); | ||
// => 'https://github.com/IonicaBizau/node-git-url-parse.git' | ||
// => "https://github.com/IonicaBizau/node-git-url-parse.git" |
@@ -0,1 +1,4 @@ | ||
// Dependencies | ||
var GitUp = require("git-up"); | ||
/** | ||
@@ -10,8 +13,17 @@ * GitUrlParse | ||
* | ||
* - `protocol` (String): The url protocol. | ||
* - `protocols` (Array): An array with the url protocols (usually it has one element). | ||
* - `port` (null|Number): The domain port. | ||
* - `resource` (String): The url domain (including subdomains). | ||
* - `user` (String): The authentication user (usually for ssh urls). | ||
* - `pathname` (String): The url pathname. | ||
* - `hash` (String): The url hash. | ||
* - `search` (String): The url querystring value. | ||
* - `href` (String): The input url. | ||
* - `protocol` (String): The git url protocol. | ||
* - `token` (String): The oauth token (could appear in the https urls). | ||
* - `source` (String): The Git provider (e.g. `"github.com"`). | ||
* - `owner` (String): The repository owner. | ||
* - `name` (String): The repository name. | ||
* - `_` (String): The original url which was parsed. | ||
* - `toString` (Function): A function to stringify the parsed url into another url type. | ||
* - `organization` (String): The organization the owner belongs to. This is CloudForge specific. | ||
*/ | ||
@@ -24,48 +36,32 @@ function GitUrlParse(url) { | ||
var urlInfo = { | ||
protocol: null | ||
, source: null | ||
, owner: null | ||
, name: null | ||
, _: url | ||
, toString: function (type) { | ||
return GitUrlParse.stringify(this, type); | ||
} | ||
} | ||
, match = null | ||
var urlInfo = GitUp(url) | ||
, sourceParts = urlInfo.resource.split(".") | ||
, splits = null | ||
; | ||
// SSH protocol | ||
check_git: if (/^git\@/.test(url)) { | ||
match = url.match(/^git@(.*):(.*)\/(.*).git$/); | ||
if (!match) { break check_git; } | ||
urlInfo.source = match[1]; | ||
urlInfo.owner = match[2]; | ||
urlInfo.name = match[3]; | ||
urlInfo.protocol = "ssh"; | ||
} else | ||
urlInfo.toString = function (type) { | ||
return GitUrlParse.stringify(this, type); | ||
}; | ||
// HTTP(S) protocol | ||
check_https: if (/^https?:\/\//.test(url)) { | ||
url = url.replace(/(\/|\.git)$/, ""); | ||
match = url.match(/^(https?):\/\/(.*)\/(.*)\/(.*)\/?$/); | ||
if (!match) { break check_https; } | ||
urlInfo.protocol = match[1]; | ||
urlInfo.source = match[2]; | ||
urlInfo.owner = match[3]; | ||
urlInfo.name = match[4]; | ||
} else | ||
urlInfo.source = sourceParts.length > 2 | ||
? sourceParts.slice(-2).join(".") | ||
: urlInfo.source = urlInfo.resource | ||
; | ||
// git+ssh protocol | ||
check_gitssh: if (/^git\+ssh:\/\/git\@/.test(url)) { | ||
url = url.replace(/\.git$/, ""); | ||
match = url.match(/^git\+ssh:\/\/git\@(.*)\/(.*)\/(.*)\/?$/); | ||
if (!match) { break check_gitssh; } | ||
urlInfo.protocol = "git+ssh"; | ||
urlInfo.source = match[1]; | ||
urlInfo.owner = match[2]; | ||
urlInfo.name = match[3]; | ||
} else { | ||
urlInfo.protocol = "file"; | ||
// Feel free to add more parsers | ||
urlInfo.name = urlInfo.pathname.substring(1).replace(/\.git$/, ""); | ||
urlInfo.owner = urlInfo.user; | ||
urlInfo.organization = urlInfo.owner; | ||
switch (urlInfo.source) { | ||
case "cloudforge.com": | ||
urlInfo.owner = urlInfo.user; | ||
urlInfo.organization = sourceParts[0]; | ||
break; | ||
default: | ||
splits = urlInfo.name.split("/"); | ||
if (splits.length === 2) { | ||
urlInfo.owner = splits[0]; | ||
urlInfo.name = splits[1]; | ||
} | ||
break; | ||
} | ||
@@ -97,3 +93,3 @@ | ||
default: | ||
return obj._; | ||
return obj.href; | ||
} | ||
@@ -100,0 +96,0 @@ }; |
{ | ||
"name": "git-url-parse", | ||
"version": "3.0.0", | ||
"description": "Parses and stringifies git urls.", | ||
"version": "4.0.0", | ||
"description": "A high level git url parser for common git providers.", | ||
"main": "lib/index.js", | ||
@@ -25,7 +25,14 @@ "scripts": { | ||
"blah": { | ||
"h_img": "http://i.imgur.com/HlfMsVf.png" | ||
"h_img": "http://i.imgur.com/HlfMsVf.png" | ||
}, | ||
"directories": { | ||
"example": "example", | ||
"test": "test" | ||
}, | ||
"dependencies": { | ||
"git-up": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"mocha": "^2.2.5" | ||
} | ||
} | ||
} |
@@ -20,3 +20,3 @@ <!----------------------------------------------------------------------------> | ||
Parses and stringifies git urls. | ||
A high level git url parser for common git providers. | ||
@@ -36,22 +36,42 @@ ## Installation | ||
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git")); | ||
// => { protocol: 'ssh' | ||
// , source: 'github.com' | ||
// , owner: 'IonicaBizau' | ||
// , name: 'node-git-url-parse' | ||
// , _: 'git@github.com:IonicaBizau/node-git-url-parse.git' | ||
// , toString: [Function] } | ||
// => { | ||
// protocols: [] | ||
// , port: null | ||
// , resource: "github.com" | ||
// , user: "git" | ||
// , pathname: "/IonicaBizau/node-git-url-parse.git" | ||
// , hash: "" | ||
// , search: "" | ||
// , href: "git@github.com:IonicaBizau/node-git-url-parse.git" | ||
// , token: "" | ||
// , protocol: "ssh" | ||
// , toString: [Function] | ||
// , source: "github.com" | ||
// , name: "node-git-url-parse" | ||
// , owner: "IonicaBizau" | ||
// } { | ||
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git")); | ||
// => { protocol: 'https' | ||
// , source: 'github.com' | ||
// , owner: 'IonicaBizau' | ||
// , name: 'node-git-url-parse' | ||
// , _: 'https://github.com/IonicaBizau/node-git-url-parse.git' | ||
// , toString: [Function] } | ||
// => { | ||
// protocols: ["https"] | ||
// , port: null | ||
// , resource: "github.com" | ||
// , user: "" | ||
// , pathname: "/IonicaBizau/node-git-url-parse.git" | ||
// , hash: "" | ||
// , search: "" | ||
// , href: "https://github.com/IonicaBizau/node-git-url-parse.git" | ||
// , token: "" | ||
// , protocol: "https" | ||
// , toString: [Function] | ||
// , source: "github.com" | ||
// , name: "node-git-url-parse" | ||
// , owner: "IonicaBizau" | ||
// } | ||
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git").toString("ssh")); | ||
// => 'git@github.com:IonicaBizau/node-git-url-parse.git.git' | ||
// => "git@github.com:IonicaBizau/node-git-url-parse.git" | ||
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git").toString("https")); | ||
// => 'https://github.com/IonicaBizau/node-git-url-parse.git' | ||
// => "https://github.com/IonicaBizau/node-git-url-parse.git" | ||
@@ -70,8 +90,17 @@ ``` | ||
- **GitUrl** The `GitUrl` object containing: | ||
- `protocol` (String): The url protocol. | ||
- `protocols` (Array): An array with the url protocols (usually it has one element). | ||
- `port` (null|Number): The domain port. | ||
- `resource` (String): The url domain (including subdomains). | ||
- `user` (String): The authentication user (usually for ssh urls). | ||
- `pathname` (String): The url pathname. | ||
- `hash` (String): The url hash. | ||
- `search` (String): The url querystring value. | ||
- `href` (String): The input url. | ||
- `protocol` (String): The git url protocol. | ||
- `token` (String): The oauth token (could appear in the https urls). | ||
- `source` (String): The Git provider (e.g. `"github.com"`). | ||
- `owner` (String): The repository owner. | ||
- `name` (String): The repository name. | ||
- `_` (String): The original url which was parsed. | ||
- `toString` (Function): A function to stringify the parsed url into another url type. | ||
- `organization` (String): The organization the owner belongs to. This is CloudForge specific. | ||
@@ -78,0 +107,0 @@ ### `stringify(obj, type)` |
@@ -20,3 +20,3 @@ // Dependencies | ||
Assert.strictEqual(res.name, "node-giturlparse"); | ||
Assert.strictEqual(res._, URLS.ssh); | ||
Assert.strictEqual(res.href, URLS.ssh); | ||
Assert.strictEqual(res.toString("https"), URLS.https); | ||
@@ -35,3 +35,3 @@ Assert.strictEqual(res.toString("git+ssh"), URLS.gitSsh); | ||
Assert.strictEqual(res.name, "node-giturlparse"); | ||
Assert.strictEqual(res._, URLS.https); | ||
Assert.strictEqual(res.href, URLS.https); | ||
Assert.strictEqual(res.toString("https"), URLS.https); | ||
@@ -59,3 +59,3 @@ Assert.strictEqual(res.toString("git+ssh"), URLS.gitSsh); | ||
var res = GitUrlParse(URLS.gitSsh); | ||
Assert.strictEqual(res.protocol, "git+ssh"); | ||
Assert.strictEqual(res.protocol, "ssh"); | ||
Assert.strictEqual(res.source, "github.com"); | ||
@@ -69,1 +69,38 @@ Assert.strictEqual(res.owner, "IonicaBizau"); | ||
}); | ||
// oauth | ||
it("should parse oauth urls", function (cb) { | ||
var res = GitUrlParse("https://token:x-oauth-basic@github.com/owner/name.git"); | ||
Assert.strictEqual(res.source, "github.com"); | ||
Assert.strictEqual(res.owner, "owner"); | ||
Assert.strictEqual(res.name, "name"); | ||
cb(); | ||
}); | ||
// oauth bitbucket | ||
it("should parse Bitbucket oauth urls", function (cb) { | ||
var res = GitUrlParse("https://x-token-auth:token@bitbucket.org/owner/name.git"); | ||
Assert.strictEqual(res.source, "bitbucket.org"); | ||
Assert.strictEqual(res.owner, "owner"); | ||
Assert.strictEqual(res.name, "name"); | ||
cb(); | ||
}); | ||
// https bitbucket | ||
it("should parse Bitbucket https urls", function (cb) { | ||
var res = GitUrlParse("https://owner@bitbucket.org/owner/name"); | ||
Assert.strictEqual(res.source, "bitbucket.org"); | ||
Assert.strictEqual(res.owner, "owner"); | ||
Assert.strictEqual(res.name, "name"); | ||
cb(); | ||
}); | ||
// https cloudforge | ||
it("should parse CloudForge urls", function (cb) { | ||
var res = GitUrlParse("https://owner@organization.git.cloudforge.com/name.git"); | ||
Assert.strictEqual(res.source, "cloudforge.com"); | ||
Assert.strictEqual(res.owner, "owner"); | ||
Assert.strictEqual(res.organization, "organization"); | ||
Assert.strictEqual(res.name, "name"); | ||
cb(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17254
218
126
1
+ Addedgit-up@^1.0.0
+ Addedgit-up@1.2.1(transitive)
+ Addedis-ssh@1.4.0(transitive)
+ Addedparse-url@1.3.11(transitive)
+ Addedprotocols@1.4.82.0.1(transitive)