Function parse

  • Return an object containing the parsed components of the path.

    Use format() to reverse the result.

    Parameters

    • path: string

      Path to process

    Returns ParsedPath

    An object with the parsed path components.

    import { parse } from "@std/path/parse";
    import { assertEquals } from "@std/assert";

    if (Deno.build.os === "windows") {
    const parsedPathObj = parse("C:\\path\\to\\script.ts");
    assertEquals(parsedPathObj.root, "C:\\");
    assertEquals(parsedPathObj.dir, "C:\\path\\to");
    assertEquals(parsedPathObj.base, "script.ts");
    assertEquals(parsedPathObj.ext, ".ts");
    assertEquals(parsedPathObj.name, "script");
    } else {
    const parsedPathObj = parse("/path/to/dir/script.ts");
    parsedPathObj.root; // "/"
    parsedPathObj.dir; // "/path/to/dir"
    parsedPathObj.base; // "script.ts"
    parsedPathObj.ext; // ".ts"
    parsedPathObj.name; // "script"
    }