Socket
Socket
Sign inDemoInstall

hosted-git-info

Package Overview
Dependencies
0
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hosted-git-info

Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab


Version published
Weekly downloads
39M
decreased by-19.59%
Maintainers
2
Install size
25.0 kB
Created
Weekly downloads
 

Package description

What is hosted-git-info?

The hosted-git-info npm package is a utility for working with Git repository metadata. It allows you to parse and transform various Git repository URLs into a normalized format, extract specific parts of the URL, and generate URLs for different purposes such as cloning or browsing the repository.

What are hosted-git-info's main functionalities?

Parsing Git URLs

This feature allows you to parse a Git URL and extract components such as domain, type, user, and project.

const hostedGitInfo = require('hosted-git-info');
const info = hostedGitInfo.fromUrl('https://github.com/npm/hosted-git-info.git');
console.log(info.domain); // 'github.com'
console.log(info.type); // 'github'
console.log(info.user); // 'npm'
console.log(info.project); // 'hosted-git-info'

Generating URLs

This feature enables you to generate various URLs for browsing, cloning, or as HTTPS URLs from a parsed Git repository object.

const hostedGitInfo = require('hosted-git-info');
const info = hostedGitInfo.fromUrl('git+https://github.com/npm/hosted-git-info.git');
console.log(info.browse()); // 'https://github.com/npm/hosted-git-info'
console.log(info.https()); // 'https://github.com/npm/hosted-git-info.git'

Shortcut URLs

This feature allows you to generate shortcut URLs for quick access to the repository on supported Git hosts.

const hostedGitInfo = require('hosted-git-info');
const info = hostedGitInfo.fromUrl('github:npm/hosted-git-info');
console.log(info.shortcut()); // 'github:npm/hosted-git-info'
console.log(info.https()); // 'https://github.com/npm/hosted-git-info.git'

Other packages similar to hosted-git-info

Readme

Source

hosted-git-info

This will let you identify and transform various git hosts URLs between protocols. It also can tell you what the URL is for the raw path for particular file for direct access without git.

Usage

var hostedGitInfo = require("hosted-git-info")
var info = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git")
/* info looks like:
{
  type: "github",
  domain: "github.com",
  user: "npm",
  project: "hosted-git-info"
}
*/

If the URL can't be matched with a git host, null will be returned. We can match git, ssh and https urls. Additionally, we can match ssh connect strings (git@github.com:npm/hosted-git-info) and shortcuts (eg, github:npm/hosted-git-info). Github specifically, is detected in the case of a third, unprefixed, form: npm/hosted-git-info.

If it does match, the returned object has properties of:

  • info.type -- The short name of the service
  • info.domain -- The domain for git protocol use
  • info.user -- The name of the user/org on the git host
  • info.project -- The name of the project on the git host

And methods of:

  • info.file(path)

Given the path of a file relative to the repository, returns a URL for directly fetching it from the githost. If no committish was set then master will be used as the default.

For example hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json") would return https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json

  • info.shortcut()

eg, github:npm/hosted-git-info

  • info.browse()

eg, https://github.com/npm/hosted-git-info/tree/v1.2.0

  • info.bugs()

eg, https://github.com/npm/hosted-git-info/issues

  • info.docs()

eg, https://github.com/npm/hosted-git-info/tree/v1.2.0#readme

  • info.https()

eg, git+https://github.com/npm/hosted-git-info.git

  • info.sshurl()

eg, git+ssh://git@github.com/npm/hosted-git-info.git

  • info.ssh()

eg, git@github.com:npm/hosted-git-info.git

  • info.path()

eg, npm/hosted-git-info

  • info.getDefaultRepresentation()

Returns the default output type. The default output type is based on the string you passed in to be parsed

  • info.toString()

Uses the getDefaultRepresentation to call one of the other methods to get a URL for this resource. As such hostedGitInfo.fromUrl(url).toString() will give you a normalized version of the URL that still uses the same protocol.

Shortcuts will still be returned as shortcuts, but the special case github form of org/project will be normalized to github:org/project.

SSH connect strings will be normalized into git+ssh URLs.

Supported hosts

Currently this supports Github, Bitbucket and Gitlab. Pull requests for additional hosts welcome.

Keywords

FAQs

Last updated on 21 May 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc