basename.ts
Windows user-profile folder path reference
SHA-2567ee495c2d1ee516ffff48fb9a93267ba928b5a3486b550be73071bc14f8cc63e
MaleculeH(F)
Evidence
1// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2// This module is browser compatible.
3
4import { isWindows } from "./_os.ts";
5import { basename as posixBasename } from "./posix/basename.ts";
6import { basename as windowsBasename } from "./windows/basename.ts";
7
8/**
9 * Return the last portion of a `path`.
10 * Trailing directory separators are ignored, and optional suffix is removed.
11 *
12 * @example
13 * ```ts
14 * import { basename } from "https://deno.land/std@$STD_VERSION/path/basename.ts";
15 *
16 * basename("/home/user/Documents/"); // "Documents"
17 * basename("C:\\user\\Documents\\image.png"); // "image.png"
18 * basename("/home/user/Documents/image.png", ".png"); // "image"
19 * ```
20 *
21 * @param path - path to extract the name from.
22 * @param [suffix] - suffix to remove from extracted name.
23 */
24export function basename(path: string, suffix = ""): string {
25 return isWindows
26 ? windowsBasename(path, suffix)
27 : posixBasename(path, suffix);
28}