UNPKG

2.65 kBMarkdownView Raw
1# github-url-to-object [![Build Status](https://travis-ci.org/zeke/github-url-to-object.png?branch=master)](https://travis-ci.org/zeke/github-url-to-object)
2
3A module for node.js and browsers that extracts useful properties like `user`,
4`repo`, and `branch` from various flavors of GitHub URLs.
5
6There's also a Bitbucket equivalent to this library: [bitbucket-url-to-object](https://github.com/zeke/bitbucket-url-to-object).
7
8Check out the demo at [zeke.github.io/github-url-to-object](https://zeke.github.io/github-url-to-object).
9
10## Installation
11
12For Node.js or Browserify usage:
13
14```sh
15npm install github-url-to-object --save
16```
17
18For bower usage:
19
20```sh
21bower install github-url-to-object
22```
23
24## Usage
25
26Use whatever flavor of GitHub URL you like:
27
28```js
29var gh = require('github-url-to-object')
30
31gh('github:monkey/business')
32gh('https://github.com/monkey/business')
33gh('https://github.com/monkey/business/tree/master')
34gh('https://github.com/monkey/business/tree/master/nested/file.js')
35gh('https://github.com/monkey/business.git')
36gh('http://github.com/monkey/business')
37gh('git://github.com/monkey/business.git')
38gh('git+https://github.com/monkey/business.git')
39```
40
41Here's what you'll get:
42
43```js
44{
45 user: 'monkey',
46 repo: 'business',
47 branch: 'master',
48 tarball_url: 'https://api.github.com/repos/monkey/business/tarball/master',
49 clone_url: 'https://github.com/monkey/business',
50 https_url: 'https://github.com/monkey/business',
51 travis_url: 'https://travis-ci.org/monkey/business',
52 api_url: 'https://api.github.com/repos/monkey/business'
53 zip_url: 'https://github.com/monkey/business/archive/master.zip'
54}
55```
56
57The shorthand form lets you specify a branch:
58
59```js
60 gh('github:monkey/business#nachos')
61{
62 user: 'monkey',
63 repo: 'business',
64 branch: 'nachos',
65 https_url: 'https://github.com/monkey/business/blob/nachos',
66 tarball_url: 'https://api.github.com/repos/monkey/business/tarball/nachos',
67 clone_url: 'https://github.com/monkey/business',
68 travis_url: 'https://travis-ci.org/monkey/business?branch=nachos',
69 api_url: 'https://api.github.com/repos/monkey/business'
70 zip_url: 'https://github.com/monkey/business/archive/nachos.zip'
71}
72```
73
74If you provide a non-GitHub URL or a falsey value, you'll get `null`.
75
76### GitHub Enterprise
77
78If you're using GitHub Enterprise, pass the `enterprise` option to allow
79your non-`github.com` URL to be parsed:
80
81```js
82gh('https://ghe.example.com:heroku/heroku-flags.git', {enterprise: true})
83```
84
85## Test
86
87```sh
88npm install
89npm test
90```
91
92[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
93
94## License
95
96MIT