/** * @copyright Sister Software * @license MIT * @author Teffen Ellis, et al. */ import type { PathBuilder } from "./path-builder.js"; import type { PathDelimiter, Split, WithoutTrailingDelimiter } from "./type-utils.js"; /** * Pluck the base name from a path. */ export type PluckBasename = Split, D> extends [...infer _Head, infer Tail] ? Tail extends string ? Tail : never : never; /** * Pluck the base name from a path, less a trailing suffix when the name carries one — `PluckBasename<"a/b.txt", * ".txt">` is `"b"`. A suffix the name does not end with is left alone, as `node:path` does. */ export type PluckBasenameWithoutSuffix = string extends Suffix ? string : PluckBasename extends `${infer Name}${Suffix}` ? Name extends "" ? PluckBasename : Name : PluckBasename; /** * Return the last portion of a path. Similar to the Unix basename command. Often used to extract the file name from a * fully qualified path. * * @param path The path to evaluate. * @param suffix An optional suffix to remove from the name, e.g. `".txt"`. * * @returns The base name of the path. * @throws {TypeError} If path is not a string or {@linkcode PathBuilder}. */ export declare function basename(path: T): T extends PathBuilder ? PluckBasename : T extends string ? PluckBasename : never; export declare function basename(path: T, suffix: Suffix): T extends PathBuilder ? PluckBasenameWithoutSuffix : T extends string ? PluckBasenameWithoutSuffix : never; export default basename; //# sourceMappingURL=basename.d.ts.map