(input: string)
| 55 | } |
| 56 | |
| 57 | export function parse(input: string): Reference | undefined { |
| 58 | const cleaned = normalizeInput(input) |
| 59 | if (!cleaned) return |
| 60 | |
| 61 | const githubPrefixed = cleaned.match(/^github:([^/\s]+)\/([^/\s]+)$/) |
| 62 | if (githubPrefixed) return buildRemote({ host: "github.com", segments: [githubPrefixed[1], githubPrefixed[2]] }) |
| 63 | |
| 64 | if (!cleaned.includes("://")) { |
| 65 | const scp = cleaned.match(/^(?:[^@/\s]+@)?([^:/\s]+):(.+)$/) |
| 66 | if (scp) return buildRemote({ host: scp[1], segments: parts(scp[2]), remote: cleaned }) |
| 67 | |
| 68 | const direct = parts(cleaned) |
| 69 | if (direct.length >= 2 && hostLike(direct[0])) return buildRemote({ host: direct[0], segments: direct.slice(1) }) |
| 70 | if (direct.length === 2) return buildRemote({ host: "github.com", segments: direct }) |
| 71 | } |
| 72 | |
| 73 | try { |
| 74 | const url = new URL(cleaned) |
| 75 | if (url.protocol === "file:") return buildFile({ url, remote: cleaned }) |
| 76 | const segments = parts(url.pathname) |
| 77 | return buildRemote({ |
| 78 | host: url.host, |
| 79 | segments, |
| 80 | remote: url.host === "github.com" ? githubRemote(segments.join("/")) : cleaned, |
| 81 | protocol: url.protocol, |
| 82 | }) |
| 83 | } catch { |
| 84 | return |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | export function parseRemote(input: string): RemoteReference { |
| 89 | const reference = parse(input) |
no test coverage detected