import * as mod from "https://dotland.deno.dev/std@0.224.0/url/mod.ts";
Utilities for working with
URL
s.
This module is browser compatible.
Get basename
basename
returns the base name of a URL or URL string, optionally
removing a suffix.
import { basename } from "https://deno.land/std@0.224.0/url/basename.ts";
basename("https://deno.land/std/assert/mod.ts"); // "mod.ts"
basename(new URL("https://deno.land/std/assert/mod.ts")); // "mod.ts"
basename("https://deno.land/std/assert/mod.ts?a=b"); // "mod.ts"
basename("https://deno.land/std/assert/mod.ts#header"); // "mod.ts"
basename("https://deno.land/"); // "deno.land"
Get directory path
dirname
returns the directory path of a URL or URL string.
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"
Get file extension
extname
returns the file extension of a given URL or string with
leading period.
import { extname } from "https://deno.land/std@0.224.0/url/extname.ts";
extname("https://deno.land/std/path/mod.ts"); // ".ts"
extname("https://deno.land/std/path/mod"); // ""
extname("https://deno.land/std/path/mod.ts?a=b"); // ".ts"
extname("https://deno.land/"); // ""
Join URL paths
join
joins a base URL or URL string, and a sequence of path
segments together, then normalizes the resulting URL.
import { join } from "https://deno.land/std@0.224.0/url/join.ts";
join("https://deno.land/", "std", "path", "mod.ts").href;
// "https://deno.land/std/path/mod.ts"
join("https://deno.land", "//std", "path/", "/mod.ts").href;
// "https://deno.land/path/mod.ts"
Normalize URL
normalize
normalizes the URL or URL string, resolving ..
and
.
segments. Multiple sequential /
s are resolved into a single /
.
import { normalize } from "https://deno.land/std@0.224.0/url/normalize.ts";
normalize("https:///deno.land///std//assert//.//mod.ts").href;
// "https://deno.land/std/path/mod.ts"
normalize("https://deno.land/std/assert/../async/retry.ts").href;
// "https://deno.land/std/async/retry.ts"
Functions
Returns the base name of a URL or URL string, optionally removing a suffix. | |
Returns the directory path of a URL or URL string. | |
Returns the file extension of a given URL or string with leading period. | |
f join | Joins a base URL or URL string, and a sequence of path segments together, then normalizes the resulting URL. |
Normalizes the URL or URL string, resolving |