Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

std/url/mod.ts>extname

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

Returns the file extension of a given URL or string with leading period.

The extension is sourced from the path portion of the URL. If there is no extension, an empty string is returned.

Examples

Basic usage

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

extname("https://deno.land/std/path/mod.ts"); // ".ts"

extname("https://deno.land/std/path/mod"); // ""

extname("https://deno.land/std/path/mod.ts?a=b"); // ".ts"

extname("https://deno.land/"); // ""

Parameters

url: string | URL

The URL from which to extract the extension.

Returns

string

The extension of the URL.