1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/tests/testdata/jsr/registry/@std/url/0.220.1/join.ts
David Sherret 651e3e9e6d
fix(compile): certain jsr specifiers sometimes can't load (#23567)
When returning a jsr specifier for resolve it seems like deno core does
not work properly and hangs.

Closes https://github.com/denoland/deno/issues/23551
Closes https://github.com/denoland/deno/issues/23139
2024-04-27 21:11:57 +00:00

28 lines
981 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import { join as posixJoin } from "jsr:/@std/path@^0.220.1/posix/join";
/**
* Join a base `URL` and a series of `paths`, then normalizes the resulting URL.
*
* @example
* ```ts
* import { join } from "@std/url/join";
*
* console.log(join("https://deno.land/", "std", "path", "mod.ts").href);
* // Outputs: "https://deno.land/std/path/mod.ts"
*
* console.log(join("https://deno.land", "//std", "path/", "/mod.ts").href);
* // Outputs: "https://deno.land/path/mod.ts"
* ```
*
* @param url the base URL to be joined with the paths and normalized
* @param paths array of path segments to be joined to the base URL
* @returns a complete URL string containing the base URL joined with the paths
*/
export function join(url: string | URL, ...paths: string[]): URL {
url = new URL(url);
url.pathname = posixJoin(url.pathname, ...paths);
return url;
}