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

std/path/mod.ts>basename

The Deno Standard Library
Latest
The Standard Library has been moved to JSR. See the blog post for details.
function basename
import { basename } from "https://deno.land/std@0.224.0/path/mod.ts";

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

Examples

Example 1

import { basename } from "https://deno.land/std@0.224.0/path/basename.ts";

basename("/home/user/Documents/"); // "Documents"
basename("C:\\user\\Documents\\image.png"); // "image.png"
basename("/home/user/Documents/image.png", ".png"); // "image"

Parameters

path: string
  • path to extract the name from.
optional
suffix = [UNSUPPORTED]
  • suffix to remove from extracted name.

Returns

string