summaryrefslogtreecommitdiff
path: root/src/misc/convert-host.ts
blob: 8f2f1c7aba7c5e60ec7b1518a2684a40e12d0f97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import config from '../config';
import { toUnicode, toASCII } from 'punycode';
import { URL } from 'url';

export function getFullApAccount(username: string, host: string) {
	return host ? `${username}@${toApHost(host)}` : `${username}@${toApHost(config.host)}`;
}

export function isSelfHost(host: string) {
	if (host == null) return true;
	return toApHost(config.host) === toApHost(host);
}

export function extractDbHost(uri: string) {
	const url = new URL(uri);
	return toDbHost(url.hostname);
}

export function toDbHost(host: string) {
	if (host == null) return null;
	return toUnicode(host.toLowerCase());
}

export function toApHost(host: string) {
	if (host == null) return null;
	return toASCII(host.toLowerCase());
}