UNPKG

@oazmi/build-tools

Version:

general deno build tool scripts which I practically use in all of my typescript repos

27 lines (26 loc) 934 B
// 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`. * Trailing directory separators are ignored, and optional suffix is removed. * * @example * ```ts * import { basename } from "@std/path/basename"; * * basename("/home/user/Documents/"); // "Documents" * basename("C:\\user\\Documents\\image.png"); // "image.png" * basename("/home/user/Documents/image.png", ".png"); // "image" * ``` * * @param path - path to extract the name from. * @param [suffix] - suffix to remove from extracted name. */ export function basename(path, suffix = "") { return isWindows ? windowsBasename(path, suffix) : posixBasename(path, suffix); }