github-url-parse
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -16,2 +16,3 @@ 'use strict'; | ||
.pipe(plugins.jshint('.jshintrc')) | ||
.pipe(plugins.plumber()) | ||
.pipe(plugins.jscs()) | ||
@@ -18,0 +19,0 @@ .pipe(plugins.jshint.reporter('jshint-stylish')); |
@@ -11,4 +11,30 @@ /* | ||
exports.awesome = function() { | ||
return 'awesome'; | ||
var url = require('url'); | ||
var GITHUBCOM = 'github.com'; | ||
module.exports = function(githubURL) { | ||
var o = url.parse( githubURL ); | ||
if (o.host !== GITHUBCOM) { | ||
return null; | ||
} | ||
var paths = url.parse(o).path.split('/').filter(Boolean); | ||
var result = {}; | ||
var keys = ['user', 'repo', 'type', 'branch']; | ||
paths.forEach(function(item, index) { | ||
var k = keys[index]; | ||
if (k) { | ||
result[k] = item; | ||
} | ||
}); | ||
if (paths.length > keys.length) { | ||
result.path = paths.slice(keys.length).join('/'); | ||
} | ||
return result; | ||
}; |
{ | ||
"name": "github-url-parse", | ||
"description": "Parse a GitHub url", | ||
"version": "0.0.0", | ||
"description": "Parse the github user, repo, branch and other things from a GitHub url.", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/stefanbuck/github-url-parse", | ||
@@ -19,7 +19,3 @@ "bugs": "https://github.com/stefanbuck/github-url-parse/issues", | ||
"keywords":[], | ||
"dependencies": { | ||
"lodash": "2.4.1", | ||
"q": "2.0.2", | ||
"debug": "1.0.2" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -26,0 +22,0 @@ "gulp": "^3.6.2", |
# github-url-parse | ||
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image] [![Coverage Status][coveralls-image]][coveralls-url] | ||
Parse a GitHub url | ||
Parse the github user, repo, branch and other things from a GitHub url. | ||
@@ -17,21 +17,14 @@ | ||
```javascript | ||
var githubUrlParse = require('github-url-parse'); | ||
githubUrlParse.awesome(); // "awesome" | ||
``` | ||
var gitHubUrlParse = require('github-url-parse'); | ||
## API | ||
var github = gitHubUrlParse('https://github.com/stefanbuck/github-url-parse/blob/master/lib/index.js'); | ||
_(Coming soon)_ | ||
console.log('user:' + github.user); // stefanbuck | ||
console.log('repo:' + github.repo); // github-url-parse | ||
console.log('branch:' + github.branch); // master | ||
console.log('path:' + github.path); // lib/index.js | ||
console.log('type:' + github.type); // blob | ||
``` | ||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [gulp](http://gulpjs.com/). | ||
## Release History | ||
_(Nothing yet)_ | ||
## License | ||
@@ -38,0 +31,0 @@ |
@@ -8,6 +8,59 @@ 'use strict'; | ||
it('should be awesome', function () { | ||
githubUrlParse.awesome().should.equal('awesome'); | ||
it('with google.com', function () { | ||
assert.equal(githubUrlParse('http://google.com', null)); | ||
}); | ||
it('with github.com', function () { | ||
assert.notEqual(githubUrlParse('http://github.com', null)); | ||
}); | ||
it('with username', function () { | ||
githubUrlParse('http://github.com/stefanbuck').should.eql({ | ||
user:'stefanbuck' | ||
}); | ||
}); | ||
it('with repo', function () { | ||
githubUrlParse('http://github.com/stefanbuck/github-url-parse').should.eql({ | ||
user:'stefanbuck', | ||
repo: 'github-url-parse' | ||
}); | ||
}); | ||
it('with type', function () { | ||
githubUrlParse('http://github.com/stefanbuck/github-url-parse/tree').should.eql({ | ||
user:'stefanbuck', | ||
repo: 'github-url-parse', | ||
type: 'tree' | ||
}); | ||
}); | ||
it('with branch', function () { | ||
githubUrlParse('http://github.com/stefanbuck/github-url-parse/tree/master').should.eql({ | ||
user:'stefanbuck', | ||
repo: 'github-url-parse', | ||
branch: 'master', | ||
type: 'tree' | ||
}); | ||
}); | ||
it('with path', function () { | ||
githubUrlParse('http://github.com/stefanbuck/github-url-parse/tree/master/lib/utils').should.eql({ | ||
user:'stefanbuck', | ||
repo: 'github-url-parse', | ||
branch: 'master', | ||
path: 'lib/utils', | ||
type: 'tree' | ||
}); | ||
}); | ||
it('with file file', function () { | ||
githubUrlParse('https://github.com/stefanbuck/github-url-parse/blob/master/lib/index.js').should.eql({ | ||
user:'stefanbuck', | ||
repo: 'github-url-parse', | ||
branch: 'master', | ||
path: 'lib/index.js', | ||
type: 'blob' | ||
}); | ||
}); | ||
}); |
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
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
parse-github-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
8101
0
144
0
10
43
- Removeddebug@1.0.2
- Removedlodash@2.4.1
- Removedq@2.0.2
- Removedasap@1.0.0(transitive)
- Removedcollections@2.0.3(transitive)
- Removeddebug@1.0.2(transitive)
- Removedlodash@2.4.1(transitive)
- Removedmini-map@1.0.0(transitive)
- Removedms@0.6.2(transitive)
- Removedpop-arrayify@1.0.0(transitive)
- Removedpop-clear@1.0.0(transitive)
- Removedpop-clone@1.0.1(transitive)
- Removedpop-compare@1.0.0(transitive)
- Removedpop-equals@1.0.0(transitive)
- Removedpop-has@1.0.0(transitive)
- Removedpop-hash@1.0.1(transitive)
- Removedpop-iterate@1.0.1(transitive)
- Removedpop-observe@2.0.2(transitive)
- Removedpop-swap@1.0.0(transitive)
- Removedpop-zip@1.0.0(transitive)
- Removedq@2.0.2(transitive)
- Removedregexp-escape@0.0.1(transitive)
- Removedweak-map@1.0.8(transitive)