mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-11 10:57:07 +00:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
interface BuildAbsoluteExplorerPathInput {
|
|
workspaceRoot: string;
|
|
entryPath: string;
|
|
}
|
|
|
|
function isAbsolutePath(pathValue: string): boolean {
|
|
return (
|
|
pathValue.startsWith("/") || pathValue.startsWith("\\\\") || /^[A-Za-z]:[\\/]/.test(pathValue)
|
|
);
|
|
}
|
|
|
|
export function buildAbsoluteExplorerPath({
|
|
workspaceRoot,
|
|
entryPath,
|
|
}: BuildAbsoluteExplorerPathInput): string {
|
|
const normalizedWorkspaceRoot = workspaceRoot.trim().replace(/[\\/]+$/, "");
|
|
const normalizedEntryPath = entryPath.trim();
|
|
|
|
if (!normalizedWorkspaceRoot) {
|
|
return normalizedEntryPath;
|
|
}
|
|
|
|
if (!normalizedEntryPath || normalizedEntryPath === ".") {
|
|
return normalizedWorkspaceRoot;
|
|
}
|
|
|
|
if (isAbsolutePath(normalizedEntryPath)) {
|
|
return normalizedEntryPath;
|
|
}
|
|
|
|
const separator = normalizedWorkspaceRoot.includes("\\") ? "\\" : "/";
|
|
const segments = normalizedEntryPath.split(/[\\/]+/).filter(Boolean);
|
|
if (segments.length === 0) {
|
|
return normalizedWorkspaceRoot;
|
|
}
|
|
|
|
return `${normalizedWorkspaceRoot}${separator}${segments.join(separator)}`;
|
|
}
|