@lonu/stc
Version:
A tool for converting OpenApi/Swagger/Apifox into code.
35 lines • 1.49 kB
TypeScript
/**
* Return the directory path of a `path`.
*
* @example Usage
* ```ts
* import { dirname } from "@std/path/posix/dirname";
* import { assertEquals } from "@std/assert";
*
* assertEquals(dirname("/home/user/Documents/"), "/home/user");
* assertEquals(dirname("/home/user/Documents/image.png"), "/home/user/Documents");
* assertEquals(dirname("https://deno.land/std/path/mod.ts"), "https://deno.land/std/path");
* assertEquals(dirname(new URL("file:///home/user/Documents/image.png")), "/home/user/Documents");
* ```
*
* @example Working with URLs
*
* Only `URL` instances with the `file:` protocol are accepted. To process a
* non-`file:` URL, pass it as a string or pass its `pathname` property.
*
* ```ts
* import { dirname } from "@std/path/posix/dirname";
* import { assertEquals } from "@std/assert";
*
* assertEquals(dirname("https://deno.land/std/path/mod.ts"), "https://deno.land/std/path");
* assertEquals(dirname("https://deno.land/std/path/mod.ts?a=b"), "https://deno.land/std/path");
* assertEquals(dirname("https://deno.land/std/path/mod.ts#header"), "https://deno.land/std/path");
* assertEquals(dirname(new URL("https://deno.land/std/path/mod.ts").pathname), "/std/path");
* ```
*
* @param path The path to get the directory from.
* @returns The directory path.
* @throws {TypeError} If `path` is a `URL` instance whose protocol is not `file:`.
*/
export declare function dirname(path: string | URL): string;
//# sourceMappingURL=dirname.d.ts.map