Skip to main content
Module

std/url/extname.ts>extname

The Deno Standard Library
Latest
function extname
import { extname } from "https://deno.land/std@0.224.0/url/extname.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.