get-github-url

v1.0.4
Get a complete (or a canonical) GitHub repository URL (https or ssh) from an incomplete URL or a user/repo path
github git url string username repository ssh https

get-github-url Build Status

Get a complete (or a canonical) GitHub repository URL (https or ssh) from an incomplete URL or a user/repo path

Installation

$ npm install get-github-url --save

Usage

var getGithubUrl = require('get-github-url');

// HTTPS
getGithubUrl('facebook/react');
// => 'https://github.com/facebook/react'
getGithubUrl('github.com/facebook/react');
// => 'https://github.com/facebook/react'
getGithubUrl('[email protected]:facebook/react.git');
// => 'https://github.com/facebook/react'
getGithubUrl('//github.com/facebook/react.git');
// => 'https://github.com/facebook/react'

// SSH
getGithubUrl('facebook/react', { protocol: 'ssh' });
 // => '[email protected]:facebook/react.git'
getGithubUrl('github.com/facebook/react', { protocol: 'ssh' });
 // => '[email protected]:facebook/react.git'
getGithubUrl('[email protected]:facebook/react.git', { protocol: 'ssh' });
// => '[email protected]:facebook/react.git'
getGithubUrl('//github.com/facebook/react.git', { protocol: 'ssh' });
// => '[email protected]:facebook/react.git'

// Prepare URL for cloning:
getGithubUrl('facebook/react', { cloning: true });
// => 'https://github.com/facebook/react.git'
getGithubUrl('facebook/react', { cloning: true, ssh: true });
// => '[email protected]:facebook/react.git'

API

getGithubUrl(input, options)

Get a complete (or a canonical) GitHub repository URL (https or ssh) from an incomplete URL or a user/repo path

Params

  • String input: a URL or a user/repo path
  • Object options: An object containing the following fields:
    • protocol (String): A format of returned URL. Possible values: ssh (https is used by default)
    • cloning (Boolean): Make a URL acceptable for git clone command

Return

  • String | Null: A valid GitHub URL or null

License

MIT © Philipp Alferov

npm i get-github-url

Metadata

  • MIT
  • >=0.10.0
  • Philipp Alferov
  • released 10/24/2015

Downloads

Maintainers