summaryrefslogtreecommitdiff
path: root/tests/registry/jsr/@std/url/0.220.1/normalize.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/registry/jsr/@std/url/0.220.1/normalize.ts')
-rw-r--r--tests/registry/jsr/@std/url/0.220.1/normalize.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/registry/jsr/@std/url/0.220.1/normalize.ts b/tests/registry/jsr/@std/url/0.220.1/normalize.ts
new file mode 100644
index 000000000..dc2305701
--- /dev/null
+++ b/tests/registry/jsr/@std/url/0.220.1/normalize.ts
@@ -0,0 +1,28 @@
+// 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;
+}