MCPcopy
hub / github.com/xintaofei/codeg / languageFromPath

Function languageFromPath

src/lib/language-detect.ts:215–235  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

213}
214
215export function languageFromPath(path: string): string {
216 const lower = path.toLowerCase()
217 const basename = lower.split(/[\\/]/).pop() ?? lower
218
219 if (BASENAME_MAP[basename]) {
220 return BASENAME_MAP[basename]
221 }
222
223 // Dockerfile.dev / Dockerfile.prod / Dockerfile.test — common multi-stage
224 // naming where the suffix is the build target rather than a file extension.
225 if (basename.startsWith("dockerfile.")) {
226 return "dockerfile"
227 }
228
229 const dotIdx = basename.lastIndexOf(".")
230 if (dotIdx === -1 || dotIdx === basename.length - 1) {
231 return "plaintext"
232 }
233 const ext = basename.slice(dotIdx + 1)
234 return EXTENSION_MAP[ext] ?? "plaintext"
235}

Callers 6

CommitWorkspaceFunction · 0.90
StashWorkspaceFunction · 0.90
PushWorkspaceFunction · 0.90
MergeWorkspaceFunction · 0.90
WorkspaceProviderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected