mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 22:23:09 +02:00
1331f0b953
> New application code should use the WHATWG API.
25 lines
691 B
TypeScript
25 lines
691 B
TypeScript
import config from '../config';
|
|
import { toASCII } from 'punycode';
|
|
|
|
export function getFullApAccount(username: string, host: string | null) {
|
|
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.host)}`;
|
|
}
|
|
|
|
export function isSelfHost(host: string) {
|
|
if (host == null) return true;
|
|
return toPuny(config.host) === toPuny(host);
|
|
}
|
|
|
|
export function extractDbHost(uri: string) {
|
|
const url = new URL(uri);
|
|
return toPuny(url.hostname);
|
|
}
|
|
|
|
export function toPuny(host: string) {
|
|
return toASCII(host.toLowerCase());
|
|
}
|
|
|
|
export function toPunyNullable(host: string | null | undefined): string | null {
|
|
if (host == null) return null;
|
|
return toASCII(host.toLowerCase());
|
|
}
|