dirname

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

function

function dirname(path: string | URL): string

Return the directory path of a path.

path: string | URL

Path to extract the directory from. When passed as a URL instance, its protocol must be file:. For other protocols, pass the URL as a string or pass its pathname property.

Returns

The directory path.

Example: Usage

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

if (Ende.build.os === "windows") {
  assertEquals(dirname("C:\\home\\user\\Documents\\image.png"), "C:\\home\\user\\Documents");
  assertEquals(dirname(new URL("file:///C:/home/user/Documents/image.png")), "C:\\home\\user\\Documents");
} else {
  assertEquals(dirname("/home/user/Documents/image.png"), "/home/user/Documents");
  assertEquals(dirname(new URL("file:///home/user/Documents/image.png")), "/home/user/Documents");
}

Source