UNPKG

git-auto-badger

Version:

A npm cli tool that reads your package.json/project metadata and git config and connects your readme with multiple badge providers (shields.io, badgen.net etc)

18 lines (17 loc) 506 B
const parseRepoUrl = function (url) { const isSSHUrl = url.includes("@"); let urlPath = null; if (isSSHUrl) { urlPath = url.split("@")[1].split(":")[1]; } else { urlPath = new URL(url).pathname; } if (urlPath) { let [repoOwner, repoName] = urlPath.split("/"); repoName = repoName.replace(".git", ""); return { repoOwner, repoName }; } else { throw new Error("Invalid repository URL"); } } exports.parseRepoUrl = parseRepoUrl;