Function relative

  • Return the relative path from from to to based on current working directory.

    Parameters

    • from: string

      Path in current working directory.

    • to: string

      Path in current working directory.

    Returns string

    The relative path from from to to.

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

    if (Deno.build.os === "windows") {
    const path = relative("C:\\foobar\\test\\aaa", "C:\\foobar\\impl\\bbb");
    assertEquals(path, "..\\..\\impl\\bbb");
    } else {
    const path = relative("/data/foobar/test/aaa", "/data/foobar/impl/bbb");
    assertEquals(path, "../../impl/bbb");
    }