Skip to main content
Module

std/url/dirname.ts>dirname

The Deno Standard Library
Latest
function dirname
import { dirname } from "https://deno.land/std@0.224.0/url/dirname.ts";

Returns the directory path of a URL or URL string.

The 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.

Examples

Basic usage

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

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

dirname("https://deno.land/").href; // "https://deno.land"

Parameters

url: string | URL

URL to extract the directory from.

Returns

The directory path of the URL.