Socket
Socket
Sign inDemoInstall

github-url-from-username-repo

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-url-from-username-repo - npm Package Compare versions

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)
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc