github-url-from-username-repo
Advanced tools
Comparing version 0.2.0 to 1.0.0
11
index.js
module.exports = getUrl | ||
function getUrl (r) { | ||
function getUrl (r, forBrowser) { | ||
if (!r) return null | ||
if (/^[\w-]+\/[\w\.-]+$/.test(r)) | ||
if (/^[\w-]+\/[\w\.-]+(#[a-z0-9]*)?$/.test(r)) { | ||
if (forBrowser) | ||
r = r.replace("#", "/tree/") | ||
return "https://github.com/" + r | ||
else | ||
return null | ||
} | ||
return null | ||
} |
{ | ||
"name": "github-url-from-username-repo", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Create urls from username/repo", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,9 @@ [![Build Status](https://travis-ci.org/robertkowalski/github-url-from-username-repo.png?branch=master)](https://travis-ci.org/robertkowalski/github-url-from-username-repo) | ||
## API | ||
### getUrl(url, [forBrowser]) | ||
Get's the url normalized for npm. | ||
If `forBrowser` is true, return a GitHub url that is usable in a webbrowser. | ||
## Usage | ||
@@ -13,4 +20,4 @@ | ||
var getUrl = require("github-url-from-username-repo") | ||
getUrl("visionmedia/express") // git://github.com/visionmedia/express | ||
getUrl("visionmedia/express") // https://github.com/visionmedia/express | ||
``` | ||
``` |
@@ -21,4 +21,4 @@ var assert = require("assert") | ||
it("works with .", function () { | ||
var url = getUrl("component/downloader.js") | ||
assert.equal("https://github.com/component/downloader.js", url) | ||
var url = getUrl("component/.download.er.js.") | ||
assert.equal("https://github.com/component/.download.er.js.", url) | ||
}) | ||
@@ -35,2 +35,26 @@ | ||
}) | ||
it("can handle branches with #", function () { | ||
var url = getUrl( | ||
"component/entejs#1c3e1fe71640b4b477f04d947bd53c473799b277") | ||
assert.equal("https://github.com/component/entejs#1c3e1fe71640b" + | ||
"4b477f04d947bd53c473799b277", url) | ||
}) | ||
describe("browser mode", function () { | ||
it("is able to return urls for branches", function () { | ||
var url = getUrl( | ||
"component/entejs#1c3e1fe71640b4b477f04d947bd53c473799b277", true) | ||
assert.equal("https://github.com/component/entejs/tree/1c3e1fe71640b" + | ||
"4b477f04d947bd53c473799b277", url) | ||
}) | ||
it("is able to return urls without a branch for the browser", function () { | ||
var url = getUrl( | ||
"component/entejs", true) | ||
assert.equal("https://github.com/component/entejs", url) | ||
}) | ||
}) | ||
}) |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4821
57
1
22