Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/esm/path/index.js>basename

A JavaScript extension package for building strong and modern applications.
Latest
function basename
import { basename } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/path/index.js";

Return the last portion of the given path. Trailing directory separators are ignored, and optional suffix is removed.

Examples

Example 1

import { basename } from "@ayonli/jsext/path";

console.log(basename("/foo/bar")); // "bar"
console.log(basename("c:\\foo\\bar")); // "bar"
console.log(basename("file:///foo/bar")); // "bar"
console.log(basename("http://example.com/foo/bar")); // "bar"
console.log(basename("http://example.com/foo/bar?foo=bar#baz")); // "bar"
console.log(basename("http://example.com/foo/bar.txt?foo=bar#baz", ".txt")); // "bar"

Parameters

path
optional
suffix = [UNSUPPORTED]