Skip to main content

@std/url@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function dirname
dirname(url: string | URL): URL

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 "@std/url/dirname";

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 to extract the directory from.

Return Type

a new URL containing the directory path of the URL.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/url

Import symbol

import { dirname } from "@std/url";
or

Import directly with a jsr specifier

import { dirname } from "jsr:@std/url";