MCPcopy
hub / github.com/graphif/project-graph / absolute2file

Function absolute2file

app/src/utils/pathString.tsx:22–39  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

20 * @returns
21 */
22 export function absolute2file(path: string): string {
23 const fam = family();
24 // const fam = "windows"; // vitest 测试时打开此行注释
25
26 if (fam === "windows") {
27 path = path.replace(/\\/g, "/");
28 }
29 const file = path.split("/").pop();
30 if (!file) {
31 throw new Error("Invalid path");
32 }
33 const parts = file.split(".");
34 if (parts.length > 1) {
35 return parts.slice(0, -1).join(".");
36 } else {
37 return file;
38 }
39 }
40
41 /**
42 * 根据文件的绝对路径,获取当前文件所在目录的路径

Callers

nothing calls this directly

Calls 3

familyFunction · 0.90
joinMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected