MCPcopy Create free account
hub / github.com/coder/mux / splitAbbreviated

Method splitAbbreviated

src/node/utils/paths.main.ts:161–175  ·  view source on GitHub ↗

* Split an abbreviated path into directory path and basename

(filePath: string)

Source from the content-addressed store, hash-verified

159 * Split an abbreviated path into directory path and basename
160 */
161 static splitAbbreviated(filePath: string): { dirPath: string; basename: string } {
162 if (!filePath || typeof filePath !== "string") {
163 return { dirPath: "", basename: filePath };
164 }
165
166 const sep = isWindowsPlatform() ? (filePath.includes("\\") ? "\\" : "/") : "/";
167 const lastSlash = filePath.lastIndexOf(sep);
168 if (lastSlash === -1) {
169 return { dirPath: "", basename: filePath };
170 }
171 return {
172 dirPath: filePath.slice(0, lastSlash + 1),
173 basename: filePath.slice(lastSlash + 1),
174 };
175 }
176
177 /**
178 * Format home directory path for display (shows ~ on Unix, full path on Windows)

Callers 1

paths.test.tsFile · 0.45

Calls 1

isWindowsPlatformFunction · 0.70

Tested by

no test coverage detected