mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
29 lines
641 B
TypeScript
29 lines
641 B
TypeScript
import urlparse from 'url';
|
|
|
|
export function makeUrlAbsolute(base: string, relative: string): string {
|
|
const relativeParsed = urlparse.parse(relative);
|
|
|
|
if (relativeParsed.host === null) {
|
|
return urlparse.resolve(base, relative);
|
|
}
|
|
|
|
return relative;
|
|
}
|
|
|
|
export function makeUrlSecure(url: string): string {
|
|
return url.replace(/^http:/, 'https:');
|
|
}
|
|
|
|
export function parseUrl(url: string): string {
|
|
return urlparse.parse(url).hostname || '';
|
|
}
|
|
|
|
export function getProvider(host: string): string {
|
|
return host
|
|
.replace(/www[a-zA-Z0-9]*\./, '')
|
|
.replace('.co.', '.')
|
|
.split('.')
|
|
.slice(0, -1)
|
|
.join(' ');
|
|
}
|