/** * @copyright Sister Software * @license MIT * @author Teffen Ellis, et al. */ import { PathBuilder } from "./path-builder.js"; import type { Join, PathDelimiter, Split, WithoutTrailingDelimiter } from "./type-utils.js"; /** * Pluck the directory name from a path, e.g., the parent directory. Matches Node's `path.dirname`: a top-level entry * resolves to the root, a bare name resolves to the current directory, and the root is its own parent. * * ```ts * type Test1 = PluckDirname<"path/to/file"> // "path/to" * type Test2 = PluckDirname<"/foo"> // "/" * type Test3 = PluckDirname<"path"> // "." * type Test4 = PluckDirname<"/"> // "/" * ``` */ export type PluckDirname = Split, D> extends [...infer Head extends string[], infer _Last] ? Head extends [] ? T extends `${D}${string}` ? "/" : "." : Head extends [""] ? "/" : Join : never; /** * Return the directory name of a path. Similar to the Unix dirname command. * * @returns The directory name of the path. * @throws {TypeError} If path is not a string or {@linkcode PathBuilder}. */ export declare function dirname(path: T): T extends PathBuilder ? PathBuilder> : T extends string ? PluckDirname : never; export default dirname; //# sourceMappingURL=dirname.d.ts.map