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

std/url/mod.ts>dirname

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

Return the directory path of a URL. A directory path is the portion of a URL up to but excluding the final path segment. The final path segment, along with any query or hash values are removed. If there is no path segment then the URL origin is returned. Example, for the URL https://deno.land/std/path/mod.ts, the directory path is https://deno.land/std/path.

Examples

Example 1

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

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

Parameters

url: string | URL
  • url to extract the directory from.

Returns

a new URL containing the directory path of the URL.