import { join } from "https://deno.land/std@0.172.0/path/mod.ts";
import { homeDir } from "https://crux.land/home@0.2.0";

export function expand(path: string) {
  const firstTwo = path.substring(0, 2);
  if (firstTwo === "~/" || firstTwo === "~\\") {
    const home = homeDir();
    if (!home) {
      throw new Error("Could not resolve user home directory!");
    }
    return join(home, path.substring(2).replace(/^[\/\\]+/g, ""));
  }
  return path;
}
