Open History to see the last commit
1export function isWindowsDrivePath(value: string): boolean {
2 return /^[a-zA-Z]:([/\\]|$)/.test(value);
3}
4
5export function isUncPath(value: string): boolean {
6 return value.startsWith("\\\\");
7}
8
9export function isWindowsAbsolutePath(value: string): boolean {
10 return isUncPath(value) || isWindowsDrivePath(value);
11}
12
13export function isExplicitRelativePath(value: string): boolean {
14 return (
15 value === "." ||
16 value === ".." ||
17 value.startsWith("./") ||
18 value.startsWith("../") ||
19 value.startsWith(".\\") ||
20 value.startsWith("..\\")
21 );
22}
23
24function isRootPath(value: string): boolean {
25 return value === "/" || value === "\\" || /^[a-zA-Z]:[/\\]?$/.test(value);
26}
27
28function trimTrailingPathSeparators(value: string): string {
29 if (value.length === 0 || isRootPath(value)) {
30 return value;
31 }
32 const trimmed = value.startsWith("/")
33 ? value.replace(/\/+$/g, "")
34 : value.replace(/[\\/]+$/g, "");
35 if (trimmed.length === 0) {
36 return value;
37 }
38 return /^[a-zA-Z]:$/.test(trimmed) ? `${trimmed}\\` : trimmed;
39}
40
41export function normalizeProjectPathForDispatch(value: string): string {
42 return trimTrailingPathSeparators(value.trim());
43}
44
45export function normalizeProjectPathForComparison(value: string): string {
46 const normalized = normalizeProjectPathForDispatch(value);
47 if (isWindowsDrivePath(normalized) || isUncPath(normalized)) {
48 return normalized.replaceAll("/", "\\").toLowerCase();
49 }
50 return normalized;
51}