mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
bb8bfd0c9e
(cherry picked from commit 94d20f1bdc)
29 lines
629 B
TypeScript
29 lines
629 B
TypeScript
import { parse, resolve } from 'node:url';
|
|
|
|
export function makeUrlAbsolute(base: string, relative: string): string {
|
|
const relativeParsed = parse(relative);
|
|
|
|
if (relativeParsed.host === null) {
|
|
return resolve(base, relative);
|
|
}
|
|
|
|
return relative;
|
|
}
|
|
|
|
export function makeUrlSecure(url: string): string {
|
|
return url.replace(/^http:/, 'https:');
|
|
}
|
|
|
|
export function parseUrl(url: string): string {
|
|
return parse(url).hostname || '';
|
|
}
|
|
|
|
export function getProvider(host: string): string {
|
|
return host
|
|
.replace(/www[a-zA-Z0-9]*\./, '')
|
|
.replace('.co.', '.')
|
|
.split('.')
|
|
.slice(0, -1)
|
|
.join(' ');
|
|
}
|