CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-hosted-git-info

Provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

url-generation.mddocs/

URL Format Generation

Generate different URL formats for git operations, browsing, file access, and downloads from a parsed GitHost instance.

Capabilities

SSH URL Generation

Generate SSH format URLs for git operations.

/**
 * Generate SSH format URL (git@host:user/repo.git)
 * @param {object} [opts] - Options object
 * @param {boolean} [opts.noCommittish] - Exclude committish from URL
 * @returns {string} SSH URL
 */
ssh(opts);

/**
 * Generate SSH URL with git+ssh protocol
 * @param {object} [opts] - Options object  
 * @param {boolean} [opts.noCommittish] - Exclude committish from URL
 * @returns {string} SSH URL with protocol
 */
sshurl(opts);

Usage Examples:

const hostedGitInfo = require("hosted-git-info");

const info = hostedGitInfo.fromUrl("github:npm/hosted-git-info#v1.0.0");

// SSH format
console.log(info.ssh());
// Result: "git@github.com:npm/hosted-git-info.git#v1.0.0"

// SSH URL format
console.log(info.sshurl());
// Result: "git+ssh://git@github.com/npm/hosted-git-info.git#v1.0.0"

// Without committish
console.log(info.ssh({ noCommittish: true }));
// Result: "git@github.com:npm/hosted-git-info.git"

HTTPS URL Generation

Generate HTTPS URLs for git operations.

/**
 * Generate HTTPS git URL
 * @param {object} [opts] - Options object
 * @param {boolean} [opts.noCommittish] - Exclude committish from URL
 * @param {boolean} [opts.noGitPlus] - Exclude 'git+' prefix from URL
 * @returns {string} HTTPS URL
 */
https(opts);

/**
 * Generate git protocol URL
 * @param {object} [opts] - Options object
 * @param {boolean} [opts.noCommittish] - Exclude committish from URL
 * @returns {string} Git protocol URL
 */
git(opts);

Usage Examples:

const info = hostedGitInfo.fromUrl("npm/hosted-git-info#v1.0.0");

// HTTPS format
console.log(info.https());
// Result: "git+https://github.com/npm/hosted-git-info.git#v1.0.0"

// Without git+ prefix
console.log(info.https({ noGitPlus: true }));
// Result: "https://github.com/npm/hosted-git-info.git#v1.0.0"

// Git protocol
console.log(info.git());
// Result: "git://github.com/npm/hosted-git-info.git#v1.0.0"

Browse URL Generation

Generate web browsable URLs for viewing repositories and files.

/**
 * Generate browsable web URL
 * @param {string} [path] - Optional path within repository
 * @param {string} [fragment] - Optional fragment/anchor
 * @param {object} [opts] - Options object
 * @returns {string} Browse URL
 */
browse(path, fragment, opts);

/**
 * Generate browsable web URL for a specific file
 * @param {string} path - Path to file within repository
 * @param {string} [fragment] - Optional fragment/anchor
 * @param {object} [opts] - Options object
 * @returns {string} Browse file URL
 */
browseFile(path, fragment, opts);

Usage Examples:

const info = hostedGitInfo.fromUrl("github:npm/hosted-git-info#v1.0.0");

// Browse repository
console.log(info.browse());
// Result: "https://github.com/npm/hosted-git-info/tree/v1.0.0"

// Browse specific path
console.log(info.browse("lib"));
// Result: "https://github.com/npm/hosted-git-info/tree/v1.0.0/lib"

// Browse with fragment
console.log(info.browse("README.md", "installation"));
// Result: "https://github.com/npm/hosted-git-info/tree/v1.0.0/README.md#installation"

// Browse specific file (uses blob instead of tree for GitHub)
console.log(info.browseFile("package.json"));
// Result: "https://github.com/npm/hosted-git-info/blob/v1.0.0/package.json"

File Access URL Generation

Generate URLs for direct file access and editing.

/**
 * Generate raw file access URL
 * @param {string} path - Path to file within repository
 * @param {object} [opts] - Options object
 * @param {boolean} [opts.noCommittish] - Use HEAD instead of specific committish
 * @returns {string} Raw file URL
 */
file(path, opts);

/**
 * Generate file edit URL
 * @param {string} path - Path to file within repository
 * @param {object} [opts] - Options object
 * @returns {string} Edit file URL
 */
edit(path, opts);

Usage Examples:

const info = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0");

// Raw file access
console.log(info.file("package.json"));
// Result: "https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json"

// File edit URL
console.log(info.edit("README.md"));
// Result: "https://github.com/npm/hosted-git-info/edit/v1.0.0/README.md"

// Use HEAD instead of specific committish
console.log(info.file("package.json", { noCommittish: true }));
// Result: "https://raw.githubusercontent.com/npm/hosted-git-info/HEAD/package.json"

Shortcut and Path Generation

Generate shortened formats for the repository.

/**
 * Generate shortcut format
 * @param {object} [opts] - Options object
 * @param {boolean} [opts.noCommittish] - Exclude committish from URL
 * @returns {string} Shortcut format
 */
shortcut(opts);

/**
 * Generate path format
 * @param {object} [opts] - Options object
 * @param {boolean} [opts.noCommittish] - Exclude committish from URL
 * @returns {string} Path format
 */
path(opts);

Usage Examples:

const info = hostedGitInfo.fromUrl("https://github.com/npm/hosted-git-info.git#v1.0.0");

// Shortcut format
console.log(info.shortcut());
// Result: "github:npm/hosted-git-info#v1.0.0"

// Path format
console.log(info.path());
// Result: "npm/hosted-git-info#v1.0.0"

// Without committish
console.log(info.shortcut({ noCommittish: true }));
// Result: "github:npm/hosted-git-info"

Documentation and Issues URLs

Generate URLs for documentation and issue tracking.

/**
 * Generate documentation URL
 * @param {object} [opts] - Options object
 * @returns {string} Documentation URL
 */
docs(opts);

/**
 * Generate issues/bugs URL
 * @param {object} [opts] - Options object
 * @returns {string} Issues URL
 */
bugs(opts);

Usage Examples:

const info = hostedGitInfo.fromUrl("npm/hosted-git-info#v1.0.0");

// Documentation URL (typically README)
console.log(info.docs());
// Result: "https://github.com/npm/hosted-git-info/tree/v1.0.0#readme"

// Issues URL
console.log(info.bugs());
// Result: "https://github.com/npm/hosted-git-info/issues"

Archive Downloads

Generate URLs for downloading repository archives.

/**
 * Generate tarball download URL
 * @param {object} [opts] - Options object
 * @returns {string} Tarball download URL
 */
tarball(opts);

Usage Examples:

const info = hostedGitInfo.fromUrl("github:npm/hosted-git-info#v1.0.0");

// Tarball download
console.log(info.tarball());
// Result: "https://codeload.github.com/npm/hosted-git-info/tar.gz/v1.0.0"

// Without specific committish (uses HEAD)
const info2 = hostedGitInfo.fromUrl("github:npm/hosted-git-info");
console.log(info2.tarball());
// Result: "https://codeload.github.com/npm/hosted-git-info/tar.gz/HEAD"

String Representation

Get the default string representation of the GitHost instance.

/**
 * Get default representation type
 * @returns {string} Default representation type
 */
getDefaultRepresentation();

/**
 * Get string representation using default format
 * @param {object} [opts] - Options object
 * @returns {string} String representation
 */
toString(opts);

/**
 * Get hash fragment for committish
 * @returns {string} Hash fragment
 */
hash();

Usage Examples:

const info1 = hostedGitInfo.fromUrl("github:npm/hosted-git-info#v1.0.0");
console.log(info1.getDefaultRepresentation()); // "shortcut"
console.log(info1.toString()); // "github:npm/hosted-git-info#v1.0.0"

const info2 = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git");
console.log(info2.getDefaultRepresentation()); // "sshurl"
console.log(info2.toString()); // "git+ssh://git@github.com/npm/hosted-git-info.git"

// Hash fragment
console.log(info1.hash()); // "#v1.0.0"

Platform-Specific Behaviors

GitHub

  • File URLs use raw.githubusercontent.com domain
  • Browse URLs use /tree/ for directories and /blob/ for files
  • Tarball URLs use codeload.github.com domain

GitLab

  • Edit URLs use /-/edit/ path
  • Tarball URLs include ?ref= query parameter

Bitbucket

  • Uses /src/ for both tree and blob paths
  • Edit URLs append ?mode=edit query parameter

GitHub Gist

  • Special handling for gist URLs
  • No separate user in some contexts
  • Hash fragments formatted with file- prefix

Sourcehut

  • Limited functionality compared to other platforms
  • No bugs template (returns null)
  • Uses /blob/ for file access

docs

index.md

repository-info.md

url-generation.md

url-parsing.md

tile.json