24 lines
507 B
TypeScript
24 lines
507 B
TypeScript
import type { Account } from '../entities';
|
|
|
|
const getDomainFromURL = (account: Pick<Account, 'url'>): string => {
|
|
try {
|
|
const url = account.url;
|
|
return new URL(url).host;
|
|
} catch {
|
|
return '';
|
|
}
|
|
};
|
|
|
|
const guessFqn = (account: Pick<Account, 'acct' | 'url'>): string => {
|
|
const acct = account.acct;
|
|
const [user, domain] = acct.split('@');
|
|
|
|
if (domain) {
|
|
return acct;
|
|
} else {
|
|
return [user, getDomainFromURL(account)].join('@');
|
|
}
|
|
};
|
|
|
|
export { getDomainFromURL, guessFqn };
|