Skip to main content
Module

std/url/extname.ts>extname

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