(path: string)
| 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 | * 根据文件的绝对路径,获取当前文件所在目录的路径 |