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

std/url/extname.ts>extname

Deno standard library
Go to 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.202.0/url/extname.ts";

Return the extension of the URL 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

Example 1

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

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

Parameters

url: string | URL

with extension

Returns

string

extension (e.g. for url ending with index.html returns .html)