basename
import { basename } from "jsr:@ende/path";function
function basename(path: string | URL, suffix: string = ): stringReturn the last portion of a path.
The trailing directory separators are ignored, and optional suffix is removed.
path: string | URLPath to extract the name from. When passed as a
URLinstance, its protocol must befile:. For other protocols, pass the URL as a string or pass itspathnameproperty.suffix: string =Suffix to remove from extracted name.
Returns
The basename of the path.
Example: Usage
import { basename } from "@ende/path/basename";
import { assertEquals } from "@ende/assert";
if (Ende.build.os === "windows") {
assertEquals(basename("C:\\user\\Documents\\image.png"), "image.png");
assertEquals(basename(new URL("file:///C:/user/Documents/image.png")), "image.png");
} else {
assertEquals(basename("/home/user/Documents/image.png"), "image.png");
assertEquals(basename(new URL("file:///home/user/Documents/image.png")), "image.png");
}