hosted-git-info
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Hosted-git-info is a handy npm package built to provide metadata and conversions from repository urls for Git hosts like GitHub, Bitbucket, and GitLab. This utility allows you to identify and convert various Git host URLs between protocols, so you can access files directly without Git and manipulate the URLs according to your need. It can accurately match git, ssh, and https URLs—more so, ssh connect strings and shortcuts. If the URL can't be matched with a Git host, null
is returned.
The usage of the hosted-git-info npm package involves requiring the package in your JavaScript code and calling the fromUrl
function with the Git repository URL as an argument. Here's an example:
const hostedGitInfo = require("hosted-git-info")
const info = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git", opts)
In the above example, info
becomes an object with information about the git host, including the type of service, domain, user name, and project name.
Another example is using the file
method to return a URL for directly fetching a file from the given Git host. Here, if no committish was set, HEAD
is used as default.
hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")
This will return https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json
.
The package also provides various other methods like shortcut
, browse
, bugs
, docs
, https
, sshurl
, ssh
, path
, tarball
, getDefaultRepresentation
, and toString
that can be utilized per requirement.
The hosted-git-info documentation and further usage details are found within its GitHub repository readme file. From explanations on the Version Contract to the detailed usage of each method, all necessary readings are provided in depth. To access the documentation, visit the repository URL: https://github.com/npm/hosted-git-info. As of this moment, this repository supports GitHub, including Gists, Bitbucket, GitLab, and Sourcehut, but pull requests for adding support to other additional hosts are always welcome.