MCPcopy
hub / github.com/npmx-dev/npmx.dev / normalizeGitUrl

Function normalizeGitUrl

shared/utils/git-providers.ts:278–289  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

276 * Handles: git+https://, git://, git@host:path, ssh://git@host/path
277 */
278export function normalizeGitUrl(input: string): string | null {
279 const url = input
280 .trim()
281 .replace(/^git\+/, '')
282 .replace(/\.git(?=[/#?]|$)/i, '')
283 .replace(/(^|\/)[^/]+?@/, '$1') // remove "user@" from "ssh://user@host.com:..."
284 .replace(/(\.[^./]+?):/, '$1/') // change ".com:" to ".com/" from "ssh://user@host.com:..."
285 .replace(/^git:\/\//, 'https://')
286 .replace(/^ssh:\/\//, 'https://')
287 if (!url) return null
288 return url.includes('://') ? url : `https://${url}`
289}
290
291export function parseRepoUrl(input: string): RepoRef | null {
292 const normalized = normalizeGitUrl(input)

Callers 3

useRepositoryUrlFunction · 0.85
parseRepoUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected