parse-github-url
Parse a github URL into an object.
Install
Install with npm:
$ npm install parse-github-url --save
HEADS UP! Breaking changes in 0.3.0!!!
See the release history for details.
Why another GitHub URL parser library?
Seems like every lib I've found does too much, like both stringifying and parsing, or converts the URL from one format to another, only returns certain segments of the URL except for what I need, yields inconsistent results or has poor coverage.
Usage
var gh = require('parse-github-url');
gh('https://github.com/jonschlinkert/micromatch');
Results in:
{
"owner": "jonschlinkert",
"name": "micromatch",
"repo": "jonschlinkert/micromatch",
"branch": "master"
}
Example results
Generated results from test fixtures:
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: '1.2.3' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'branch' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'gh.pages.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.assemble.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.assemble.two.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: '1.2.3' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'v1.2.3' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'assemble',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: null,
repo: null,
repository: null,
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'tree' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master/foo/bar' }
{ host: 'assemble.github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'somefile.tar.gz' }
{ host: 'assemble.github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'somefile.zip' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'gh.pages.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: '1.2.3' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'blob' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'master' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: '1.2.3' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'feature/1.2.3' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'tarball' }
{ host: 'github.com',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb',
branch: 'zipball' }
History
v0.3.0
To be more consistent with node.js/package.json conventions, the following properties were renamed in v0.3.0
:
repo
is now name
(project name)repopath
is now repository
(project repository)user
is now owner
(project owner or org)
Related projects
You might also be interested in these projects:
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb, v0.9.0, on April 17, 2016.