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 |
|
3 | A module for node.js and browsers that extracts useful properties like `user`,
|
4 | `repo`, and `branch` from various flavors of GitHub URLs.
|
5 |
|
6 | There's also a Bitbucket equivalent to this library: [bitbucket-url-to-object](https://github.com/zeke/bitbucket-url-to-object).
|
7 |
|
8 | Check out the demo at [zeke.github.io/github-url-to-object](https://zeke.github.io/github-url-to-object).
|
9 |
|
10 | ## Installation
|
11 |
|
12 | For Node.js or Browserify usage:
|
13 |
|
14 | ```sh
|
15 | npm install github-url-to-object --save
|
16 | ```
|
17 |
|
18 | For bower usage:
|
19 |
|
20 | ```sh
|
21 | bower install github-url-to-object
|
22 | ```
|
23 |
|
24 | ## Usage
|
25 |
|
26 | Use whatever flavor of GitHub URL you like:
|
27 |
|
28 | ```js
|
29 | var gh = require('github-url-to-object')
|
30 |
|
31 | gh('github:monkey/business')
|
32 | gh('https://github.com/monkey/business')
|
33 | gh('https://github.com/monkey/business/tree/master')
|
34 | gh('https://github.com/monkey/business/tree/master/nested/file.js')
|
35 | gh('https://github.com/monkey/business.git')
|
36 | gh('http://github.com/monkey/business')
|
37 | gh('git://github.com/monkey/business.git')
|
38 | gh('git+https://github.com/monkey/business.git')
|
39 | ```
|
40 |
|
41 | Here'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 |
|
57 | The 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 |
|
74 | If you provide a non-GitHub URL or a falsey value, you'll get `null`.
|
75 |
|
76 | ### GitHub Enterprise
|
77 |
|
78 | If you're using GitHub Enterprise, pass the `enterprise` option to allow
|
79 | your non-`github.com` URL to be parsed:
|
80 |
|
81 | ```js
|
82 | gh('https://ghe.example.com:heroku/heroku-flags.git', {enterprise: true})
|
83 | ```
|
84 |
|
85 | ## Test
|
86 |
|
87 | ```sh
|
88 | npm install
|
89 | npm 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 |
|
96 | MIT
|