import { assertArgs, lastPathSegment, stripSuffix,} from "../_common/basename.ts";import { CHAR_COLON } from "../_common/constants.ts";import { stripTrailingSeparators } from "../_common/strip_trailing_separators.ts";import { isPathSeparator, isWindowsDeviceRoot } from "./_util.ts";
export function basename(path: string, suffix = ""): string { assertArgs(path, suffix);
let start = 0; if (path.length >= 2) { const drive = path.charCodeAt(0); if (isWindowsDeviceRoot(drive)) { if (path.charCodeAt(1) === CHAR_COLON) start = 2; } }
const lastSegment = lastPathSegment(path, isPathSeparator, start); const strippedSegment = stripTrailingSeparators(lastSegment, isPathSeparator); return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;}