function normalize(path: string): string { const absolute = path.startsWith("/"); const out: string[] = []; for (const segment of path.split("/")) { if (segment === "" || segment === ".") continue; if (segment === "..") { if (out.length > 0 && out[out.length - 1] !== "..") out.pop(); else if (!absolute) out.push(".."); continue; } out.push(segment); } const body = out.join("/"); if (absolute) return `/${body}`; return body === "" ? "." : body; } export function joinPath(...parts: string[]): string { const joined = parts.filter((part) => part !== "").join("/"); return joined === "" ? "." : normalize(joined); } export function dirnamePath(path: string): string { const trimmed = path.length > 1 ? path.replace(/[\\/]+$/, "") : path; const cut = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\")); if (cut < 0) return "."; if (cut === 0) return trimmed.slice(0, 1); return trimmed.slice(0, cut); } export function extnamePath(path: string): string { const cut = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")); const base = path.slice(cut + 1); const dot = base.lastIndexOf("."); return dot <= 0 ? "" : base.slice(dot); }