UNPKG

abi.js

Version:

[![typescript-icon]][typescript-link] [![license-icon]][license-link] [![status-icon]][status-link] [![ci-icon]][ci-link] [![twitter-icon]][twitter-link]

34 lines (33 loc) 1.06 kB
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. import { isWindows } from "./_os.js"; import { basename as posixBasename } from "./posix/basename.js"; import { basename as windowsBasename } from "./windows/basename.js"; /** * Return the last portion of a path. * * The trailing directory separators are ignored, and optional suffix is * removed. * * @example Usage * ```ts * import { basename } from "@std/path/basename"; * import { assertEquals } from "@std/assert"; * * if (Deno.build.os === "windows") { * assertEquals(basename("C:\\user\\Documents\\image.png"), "image.png"); * } else { * assertEquals(basename("/home/user/Documents/image.png"), "image.png"); * } * ``` * * @param path Path to extract the name from. * @param suffix Suffix to remove from extracted name. * * @returns The basename of the path. */ export function basename(path, suffix = "") { return isWindows ? windowsBasename(path, suffix) : posixBasename(path, suffix); }