npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mos-hosted-git-info

v1.0.0

Published

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

Downloads

109

Readme

@zkochan/hosted-git-info NPM version Build status for master

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

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.

Installation

This module is installed via npm:

npm install @zkochan/hosted-git-info --save

Usage

var hostedGitInfo = require('@zkochan/hosted-git-info')
var info = hostedGitInfo.fromUrl('[email protected]:npm/hosted-git-info.git')
console.log([info.type, info.domain, info.user, info.project].join('\n'))
//> github
//  github.com
//  npm
//  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 ([email protected]: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
var url = hostedGitInfo.fromUrl('[email protected]:npm/hosted-git-info.git#v1.0.0').file('package.json')
console.log(url)
//> https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json

console.log(info.shortcut())
//> github:npm/hosted-git-info

console.log(info.browse())
//> https://github.com/npm/hosted-git-info

console.log(info.bugs())
//> https://github.com/npm/hosted-git-info/issues

console.log(info.docs())
//> https://github.com/npm/hosted-git-info#readme

console.log(info.https())
//> git+https://github.com/npm/hosted-git-info.git

console.log(info.sshurl())
//> git+ssh://[email protected]/npm/hosted-git-info.git

console.log(info.ssh())
//> [email protected]:npm/hosted-git-info.git

console.log(info.path())
//> npm/hosted-git-info

console.log(info.getDefaultRepresentation())
//> sshurl

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.

License

ISC © Rebecca Turner


Dev Dependencies devDependency status for master

  • mos: A pluggable module that injects content into your markdown files via hidden JavaScript snippets
  • standard: JavaScript Standard Style
  • tap: A Test-Anything-Protocol library