parse-github-repo-url
Advanced tools
Comparing version
16
index.js
@@ -1,2 +0,1 @@ | ||
var parse = require('url').parse | ||
@@ -9,13 +8,12 @@ | ||
if (!~string.indexOf('://')) return false | ||
var url = parse(string) | ||
string = string.replace('//www.', '//') | ||
// normalize git@ and https:git@ urls | ||
string = string.replace(/^git@/, 'https://') | ||
string = string.replace(/^https:git@/, 'https://') | ||
string = string.replace('.com:', '.com/') | ||
switch (url.hostname) { | ||
case 'github.com': | ||
case 'api.github.com': | ||
case 'codeload.github.com': | ||
break | ||
default: | ||
if (!~string.indexOf('://')) { | ||
return false | ||
} | ||
var url = parse(string) | ||
@@ -22,0 +20,0 @@ var path = url.pathname.replace(/\.git$/, '') |
{ | ||
"name": "parse-github-repo-url", | ||
"description": "Parse a GitHub URL for user/project@version", | ||
"version": "1.0.0", | ||
"version": "1.2.0", | ||
"author": { | ||
@@ -16,2 +16,3 @@ "name": "Jonathan Ong", | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
@@ -18,0 +19,0 @@ "test": "mocha --reporter spec --bail" |
@@ -1,3 +0,9 @@ | ||
# Parse GitHub Repo URL | ||
# parse-github-repo-url | ||
> Parse a GitHub URL for user/project@version | ||
[](https://travis-ci.org/repo-utils/parse-github-repo-url) | ||
# Features | ||
Parse all the stupid ways you could write a GitHub URL in your damn `package.json`. | ||
@@ -8,2 +14,5 @@ Supports: | ||
- `git://` and `.git` w/ `#commit` or `@version` | ||
- `git@` and `https:git@` | ||
- `www.github.com` | ||
- `gitlab.<my company name>.com/user/repo.git` parsing | ||
- All 5 different ways you could download a freaking tarball/zipball | ||
@@ -18,3 +27,3 @@ | ||
```js | ||
var parse = require('parse-github-repo-url') | ||
var parse = require('@bahmutov/parse-github-repo-url') | ||
parse('component/emitter#1') // => ['component', 'emitter', '1'] | ||
@@ -21,0 +30,0 @@ ``` |
60
test.js
var assert = require('assert') | ||
var parse = require('.') | ||
var parse = require('./') | ||
@@ -20,2 +20,14 @@ describe('versionless', function () { | ||
}) | ||
it('works for www.github.com', function () { | ||
var url = 'https://www.github.com/component/emitter' | ||
var parsed = parse(url) | ||
assert.deepEqual(['component', 'emitter', ''], parsed) | ||
}) | ||
it('works for http://www.github.com', function () { | ||
var url = 'http://www.github.com/component/emitter' | ||
var parsed = parse(url) | ||
assert.deepEqual(['component', 'emitter', ''], parsed) | ||
}) | ||
}) | ||
@@ -41,1 +53,47 @@ | ||
}) | ||
describe('url parse', function () { | ||
var builtinUrlParse = require('url').parse | ||
it('handles https:// url', function () { | ||
var url = 'https://foo.com/bar' | ||
var parsed = builtinUrlParse(url) | ||
assert.equal('foo.com', parsed.hostname) | ||
}) | ||
it('does not handle emails', function () { | ||
var url = 'git@foo.com/bar' | ||
var parsed = builtinUrlParse(url) | ||
assert.equal(null, parsed.hostname, JSON.stringify(parsed)) | ||
}) | ||
}) | ||
describe('gitlab urls', function () { | ||
it('parses https gitlab url', function () { | ||
var url = 'https://gitlab.mycompany.com/user/test1.git' | ||
var parsed = parse(url) | ||
assert.deepEqual(['user', 'test1', ''], parsed) | ||
}) | ||
}) | ||
describe('git @ syntax', function () { | ||
it('works for git url', function () { | ||
var url = 'git@github.com:bahmutov/lazy-ass.git' | ||
var parsed = parse(url) | ||
assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed) | ||
}); | ||
it('works for https:git url', function () { | ||
var url = 'https:git@github.com:bahmutov/lazy-ass.git' | ||
var parsed = parse(url) | ||
assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed) | ||
}); | ||
}) | ||
describe('github enterprise urls', function () { | ||
it('parses https github enterprise url', function () { | ||
var url = 'https://git.mycompany.com/user/test1.git' | ||
var parsed = parse(url) | ||
assert.deepEqual(['user', 'test1', ''], parsed) | ||
}) | ||
}) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
7731
42.38%7
16.67%120
64.38%31
40.91%1
Infinity%