1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-09 15:48:16 -05:00
denoland-deno/tests/testdata/jsr/registry/@std/url/0.220.1/normalize.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
898 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import { normalize as posixNormalize } from "jsr:/@std/path@^0.220.1/posix/normalize";
/**
* Normalize the `URL`, resolving `'..'` and `'.'` segments and multiple
* `'/'`s into `'//'` after protocol and remaining into `'/'`.
*
* @example
* ```ts
* import { normalize } from "@std/url/normalize";
*
* console.log(normalize("https:///deno.land///std//assert//.//mod.ts").href);
* // Outputs: "https://deno.land/std/path/mod.ts"
*
* console.log(normalize("https://deno.land/std/assert/../async/retry.ts").href);
* // Outputs: "https://deno.land/std/async/retry.ts"
* ```
*
* @param url to be normalized
* @returns normalized URL
*/
export function normalize(url: string | URL): URL {
url = new URL(url);
url.pathname = posixNormalize(url.pathname);
return url;
}