1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-23 19:19:05 +09:00
misskey/src/misc/convert-host.ts

27 lines
718 B
TypeScript
Raw Normal View History

import { URL } from 'url';
2021-03-23 17:43:07 +09:00
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);
}
2019-03-13 11:21:16 +09:00
export function extractDbHost(uri: string) {
const url = new URL(uri);
return toPuny(url.hostname);
2019-03-13 11:21:16 +09:00
}
export function toPuny(host: string) {
return toASCII(host.toLowerCase());
}
2019-04-13 16:54:21 +09:00
export function toPunyNullable(host: string | null | undefined): string | null {
if (host == null) return null;
return toASCII(host.toLowerCase());
}