bigbuffet-rw/app/soapbox/utils/accounts.ts

35 lines
880 B
TypeScript
Raw Normal View History

import type { Account } from 'soapbox/types/entities';
2022-03-21 11:09:01 -07:00
2022-03-31 15:00:31 -07:00
const getDomainFromURL = (account: Account): string => {
try {
2022-03-31 15:00:31 -07:00
const url = account.url;
return new URL(url).host;
} catch {
return '';
}
};
2022-03-31 15:00:31 -07:00
export const getDomain = (account: Account): string => {
const domain = account.acct.split('@')[1];
return domain ? domain : getDomainFromURL(account);
};
2022-04-24 12:28:07 -07:00
export const getBaseURL = (account: Account): string => {
try {
2022-04-24 12:28:07 -07:00
return new URL(account.url).origin;
} catch {
return '';
}
};
2022-03-21 11:09:01 -07:00
export const getAcct = (account: Account, displayFqn: boolean): string => (
displayFqn === true ? account.fqn : account.acct
);
export const isLocal = (account: Account): boolean => {
const domain: string = account.acct.split('@')[1];
return domain === undefined ? true : false;
};
export const isRemote = (account: Account): boolean => !isLocal(account);