pathurl
Node.js path API but for URLs. Works on all runtimes and platforms.
Usage
All functions accept both a url string or a native URL object and always return a URL object wherever possible.
basename
Return the last portion of a url.
import { basename } from "pathurl";
basename("https://deno.land/std/assert/mod.ts");
basename("https://deno.land/");
dirname
Return the parent directory url of a url path.
import { dirname } from "pathurl";
dirname("https://deno.land/std/assert/mod.ts");
extname
Return the extension of a url.
import { extname } from "pathurl";
extname("https://deno.land/std/assert/mod.ts");
extname("https://deno.land/")
format
Generate a url from ParsedURL
object.
import { format } from "pathurl";
format({
dir: "https://deno.land/std/assert",
base: "mod.ts"
});
join
Join all given a sequence of url and paths, then normalizes the resulting url.
import { join } from "pathurl";
join("https://deno.land", "std", "assert", "mod.ts");
normalize
Normalize a url, resolving '..'
and '.'
segments and extra '/'
s (if any).
import { normalize } from "pathurl";
normalize("https://deno.land/std/assert//../async/retry.ts/");
parse
Return a ParsedURL
object of the url.
import { parse } from "pathurl";
parse("https://deno.land/std/assert/mod.ts");
relative
Return the relative url from from
to to
based on from
as base url.
import { relative } from "pathurl";
relative("https://deno.land/std/assert/mod.ts", "./equal.ts");
resolve
Resolve url and path segments into an absolute url.
import { resolve } from "pathurl";
resolve("https://deno.land", "std", "assert", "mod.ts", "../assert.ts");
strip
Strips any hash (eg. #header
) or search parameters (eg. ?foo=bar
) from the provided URL.
(Mutates the original url provided)
import { strip } from "pathurl";
const url = new URL("https://deno.land/std/assert/mod.ts?foo=bar#header");
strip(url);
Building
License
This repository uses MIT license. See LICENSE for full license text.