Socket
Socket
Sign inDemoInstall

github-url-to-object

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-url-to-object - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

21

index.js

@@ -0,21 +1,22 @@

var url = require('url')
var isUrl = require('is-url')
module.exports = function(url) {
module.exports = function(repo_url) {
if (!url) return null
if (!repo_url) return null
// bail if given a non-github URL
if (isUrl(url) && !url.match(/github\.com/)) return null
if (isUrl(repo_url) && url.parse(repo_url).hostname != "github.com") return null
var re = /^(?:https?:\/\/|git:\/\/)?(?:[^@]+@)?(gist.github.com|github.com)[:\/]([^\/]+\/[^\/]+?|[0-9]+)$/
var match = re.exec(url.replace(/\.git$/, ''));
var match = re.exec(repo_url.replace(/\.git$/, ''));
// support shorthand URLs
var parts = match ? match[2].split('/') : url.split('/')
var parts = match ? match[2].split('/') : repo_url.split('/')
return {
user: parts[0],
repo: parts[1]
};
var obj = {user: parts[0], repo: parts[1]}
};
obj.tarball_url = "https://api.github.com/repos/" + obj.user + "/" + obj.repo + "/tarball"
obj.https_url = "https://github.com/" + obj.user + "/" + obj.repo
return obj
}
{
"name": "github-url-to-object",
"version": "0.4.1",
"version": "0.5.0",
"description": "Extract username and repo name from various flavors of GitHub URLs",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,6 +7,24 @@ var mocha = require("mocha")

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')
describe("properties", function() {
var obj
before(function(){
obj = gh("git://github.com/foo-master/party-time.git")
})
it("user", function() {
assert.equal(obj.user, 'foo-master')
})
it("repo", function() {
assert.equal(obj.repo, 'party-time')
})
it("tarball_url", function() {
assert.equal(obj.tarball_url, "https://api.github.com/repos/foo-master/party-time/tarball")
})
it("https_url", function() {
assert.equal(obj.https_url, 'https://github.com/foo-master/party-time')
})
})

@@ -13,0 +31,0 @@

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