aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/locationBar/splitUrl.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/locationBar/splitUrl.ts')
-rw-r--r--packages/renderer/src/components/locationBar/splitUrl.ts62
1 files changed, 0 insertions, 62 deletions
diff --git a/packages/renderer/src/components/locationBar/splitUrl.ts b/packages/renderer/src/components/locationBar/splitUrl.ts
deleted file mode 100644
index 6e95472..0000000
--- a/packages/renderer/src/components/locationBar/splitUrl.ts
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21export type SplitResult =
22 | {
23 type: 'valid';
24 secure: boolean;
25 prefix: string;
26 host: string;
27 suffix: string;
28 }
29 | {
30 type: 'invalid';
31 value: string;
32 }
33 | {
34 type: 'empty';
35 };
36
37export default function splitUrl(urlString: string | undefined): SplitResult {
38 if (urlString === undefined || urlString === '') {
39 return { type: 'empty' };
40 }
41 let url: URL;
42 try {
43 url = new URL(urlString);
44 } catch {
45 return { type: 'invalid', value: urlString };
46 }
47 const { protocol, host, username, password, pathname, search, hash } = url;
48 if (protocol === 'http:' || protocol === 'https:') {
49 return {
50 type: 'valid',
51 secure: protocol === 'https:',
52 prefix: `${protocol}//${
53 username === ''
54 ? ''
55 : `${username}${password === '' ? '' : `:${password}`}@`
56 }`,
57 host,
58 suffix: `${pathname}${search}${hash}`,
59 };
60 }
61 return { type: 'invalid', value: urlString };
62}