1export function createURL(path, { queryParams = {} } = {}) {
2    if (typeof window === 'undefined')
3        return '';
4    const url = new URL(path, window.location.origin);
5    Object.entries(queryParams).forEach(([key, value]) => {
6        if (typeof value === 'string') {
7            url.searchParams.set(key, encodeURIComponent(value));
8        }
9        else if (value != null) {
10            // @ts-expect-error
11            url.searchParams.set(key, value);
12        }
13    });
14    return url.toString().replace(/\/$/, '');
15}
16export function parse(url) {
17    let parsed;
18    try {
19        parsed = new URL(url);
20    }
21    catch {
22        if (typeof window === 'undefined') {
23            return {
24                hostname: null,
25                path: url,
26                queryParams: {},
27                scheme: null,
28            };
29        }
30        return {
31            hostname: 'localhost',
32            path: url,
33            queryParams: {},
34            scheme: 'http',
35        };
36    }
37    const queryParams = {};
38    parsed.searchParams.forEach((value, key) => {
39        queryParams[key] = decodeURIComponent(value);
40    });
41    return {
42        hostname: parsed.hostname || null,
43        // TODO: We should probably update native to follow the default URL behavior closer.
44        path: !parsed.hostname && !parsed.pathname
45            ? null
46            : parsed.pathname === ''
47                ? null
48                : parsed.pathname.replace(/^\//, ''),
49        queryParams,
50        scheme: parsed.protocol.replace(/:$/, ''),
51    };
52}
53//# sourceMappingURL=createURL.web.js.map