What is git-url-parse?
The git-url-parse npm package is a utility for parsing Git URLs and extracting useful information from them. It supports various Git URL formats and provides methods to manipulate and retrieve different parts of the URL.
What are git-url-parse's main functionalities?
Parsing a Git URL
This feature allows you to parse a Git URL and get an object containing various parts of the URL such as the protocol, source, owner, name, and more.
const gitUrlParse = require('git-url-parse');
const parsed = gitUrlParse('https://github.com/IonicaBizau/git-url-parse.git');
console.log(parsed);
Extracting the owner and name
This feature allows you to extract specific parts of the Git URL, such as the owner and repository name.
const gitUrlParse = require('git-url-parse');
const parsed = gitUrlParse('https://github.com/IonicaBizau/git-url-parse.git');
console.log(parsed.owner); // 'IonicaBizau'
console.log(parsed.name); // 'git-url-parse'
Converting to a different URL format
This feature allows you to convert a Git URL from one format to another, such as from HTTPS to SSH.
const gitUrlParse = require('git-url-parse');
const parsed = gitUrlParse('https://github.com/IonicaBizau/git-url-parse.git');
const sshUrl = parsed.toString('ssh');
console.log(sshUrl); // 'git@github.com:IonicaBizau/git-url-parse.git'
Other packages similar to git-url-parse
parse-github-url
The parse-github-url package is a utility for parsing GitHub URLs specifically. It extracts information such as the owner, repository name, and branch. Compared to git-url-parse, it is more focused on GitHub URLs and may not support other Git hosting services.
git-url
The git-url package provides similar functionality for parsing and manipulating Git URLs. It offers methods to extract parts of the URL and convert between different URL formats. It is comparable to git-url-parse in terms of functionality but may have different API design and usage patterns.
url-parse
The url-parse package is a more general-purpose URL parsing library that can handle various types of URLs, not just Git URLs. While it can be used to parse Git URLs, it does not provide Git-specific methods and properties like git-url-parse does.
git-url-parse
A high level git url parser for common git providers.
Installation
$ npm i --save git-url-parse
Example
var GitUrlParse = require("git-url-parse");
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git"));
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git"));
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git").toString("ssh"));
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git").toString("https"));
Documentation
GitUrlParse(url)
Parses a Git url.
Params
- String
url
: The Git url to parse.
Return
- GitUrl The
GitUrl
object containing: protocols
(Array): An array with the url protocols (usually it has one element).port
(null|Number): The domain port.resource
(String): The url domain (including subdomains).user
(String): The authentication user (usually for ssh urls).pathname
(String): The url pathname.hash
(String): The url hash.search
(String): The url querystring value.href
(String): The input url.protocol
(String): The git url protocol.token
(String): The oauth token (could appear in the https urls).source
(String): The Git provider (e.g. "github.com"
).owner
(String): The repository owner.name
(String): The repository name.toString
(Function): A function to stringify the parsed url into another url type.organization
(String): The organization the owner belongs to. This is CloudForge specific.
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.
Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:
License
MIT © Ionică Bizău