Skip to content

Commit 9013029

Browse files
committed
refactor(normalizeURL): decouple from $URL
1 parent 011777a commit 9013029

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/utils.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { createURL } from "./url";
21
import { parseURL, stringifyParsedURL } from "./parse";
32
import { QueryObject, parseQuery, stringifyQuery, ParsedQuery } from "./query";
4-
import { decode } from "./encoding";
3+
import {
4+
decode,
5+
decodePath,
6+
encodeHash,
7+
encodeHost,
8+
encodeParam,
9+
encodePath,
10+
} from "./encoding";
511

612
export function isRelative(inputString: string) {
713
return ["./", "../"].some((string_) => inputString.startsWith(string_));
@@ -212,8 +218,12 @@ export function withProtocol(input: string, protocol: string): string {
212218
}
213219

214220
export function normalizeURL(input: string): string {
215-
// TODO: remove dependecny on createURL
216-
return createURL(input).toString();
221+
const parsed = parseURL(input);
222+
parsed.pathname = encodePath(decodePath(parsed.pathname));
223+
parsed.hash = encodeHash(decode(parsed.hash));
224+
parsed.host = encodeHost(decode(parsed.host));
225+
parsed.search = stringifyQuery(parseQuery(parsed.search));
226+
return stringifyParsedURL(parsed);
217227
}
218228

219229
export function resolveURL(base = "", ...inputs: string[]): string {

0 commit comments

Comments
 (0)