Skip to content

Commit

Permalink
refactor(normalizeURL): decouple from $URL
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 5, 2024
1 parent 011777a commit 9013029
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { createURL } from "./url";
import { parseURL, stringifyParsedURL } from "./parse";
import { QueryObject, parseQuery, stringifyQuery, ParsedQuery } from "./query";
import { decode } from "./encoding";
import {
decode,
decodePath,
encodeHash,
encodeHost,
encodeParam,

Check warning on line 8 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci

'encodeParam' is defined but never used

Check warning on line 8 in src/utils.ts

View workflow job for this annotation

GitHub Actions / autofix

'encodeParam' is defined but never used
encodePath,
} from "./encoding";

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

export function normalizeURL(input: string): string {
// TODO: remove dependecny on createURL
return createURL(input).toString();
const parsed = parseURL(input);
parsed.pathname = encodePath(decodePath(parsed.pathname));
parsed.hash = encodeHash(decode(parsed.hash));
parsed.host = encodeHost(decode(parsed.host));
parsed.search = stringifyQuery(parseQuery(parsed.search));
return stringifyParsedURL(parsed);
}

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

0 comments on commit 9013029

Please sign in to comment.