MCPcopy Index your code
hub / github.com/codeaashu/claude-code / extractHostFromSource

Function extractHostFromSource

src/utils/plugins/marketplaceHelpers.ts:235–268  ·  view source on GitHub ↗
(
  source: MarketplaceSource,
)

Source from the content-addressed store, hash-verified

233 * @returns The hostname string, or null if extraction fails or source type not supported
234 */
235export function extractHostFromSource(
236 source: MarketplaceSource,
237): string | null {
238 switch (source.source) {
239 case 'github':
240 // GitHub shorthand always means github.com
241 return 'github.com'
242
243 case 'git': {
244 // SSH format: user@HOST:path (e.g., git@github.com:owner/repo.git)
245 const sshMatch = source.url.match(/^[^@]+@([^:]+):/)
246 if (sshMatch?.[1]) {
247 return sshMatch[1]
248 }
249 // HTTPS format: extract hostname from URL
250 try {
251 return new URL(source.url).hostname
252 } catch {
253 return null
254 }
255 }
256
257 case 'url':
258 try {
259 return new URL(source.url).hostname
260 } catch {
261 return null
262 }
263
264 // npm, file, directory, hostPattern, pathPattern sources are not supported for hostPattern matching
265 default:
266 return null
267 }
268}
269
270/**
271 * Check if a source matches a hostPattern entry.

Callers 2

addMarketplaceSourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected