giturlparse

3.0.0 • Public • Published

git-url-parse

git-url-parse Donate now

Parses and stringifies git urls.

Installation

$ npm i git-url-parse

Example

// Dependencies
var GitUrlParse = require("git-url-parse");
 
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git"));
// => { protocol: 'ssh'
//    , source: 'github.com'
//    , owner: 'IonicaBizau'
//    , name: 'node-git-url-parse'
//    , _: 'git@github.com:IonicaBizau/node-git-url-parse.git'
//    , toString: [Function] }
 
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git"));
// => { protocol: 'https'
//    , source: 'github.com'
//    , owner: 'IonicaBizau'
//    , name: 'node-git-url-parse'
//    , _: 'https://github.com/IonicaBizau/node-git-url-parse.git'
//    , toString: [Function] }
 
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git").toString("ssh"));
// => 'git@github.com:IonicaBizau/node-git-url-parse.git.git'
 
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git").toString("https"));
// => 'https://github.com/IonicaBizau/node-git-url-parse.git'
 

Documentation

GitUrlParse(url)

Parses a Git url.

Params

  • String url: The Git url to parse.

Return

  • GitUrl The GitUrl object containing:
  • protocol (String): The url protocol.
  • source (String): The Git provider (e.g. "github.com").
  • owner (String): The repository owner.
  • name (String): The repository name.
  • _ (String): The original url which was parsed.
  • toString (Function): A function to stringify the parsed url into another url type.

stringify(obj, type)

Stringifies a GitUrl object.

Params

  • GitUrl obj: The parsed Git url object.
  • String type: The type of the stringified url (default obj.protocol).

Return

  • String The stringified url.

How to contribute

Have an idea? Found a bug? See how to contribute.

License

KINDLY © Ionică Bizău–The LICENSE file contains a copy of the license.

Readme

Keywords

Package Sidebar

Install

npm i giturlparse

Weekly Downloads

8

Version

3.0.0

License

KINDLY

Last publish

Collaborators

  • ionicabizau