relative

import { relative } from "jsr:@ende/path";

function

function relative(from: string, to: string): string

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

from: string

Path in current working directory.

to: string

Path in current working directory.

Returns

The relative path from from to to.

Example: Usage

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

if (Ende.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");
}

Source