iceshrimp-legacy/packages/calckey-js/src/acct.ts
Kaity A 37c0423da6 Incorporate calckey-js into calckey repository (#9820)
Closes #9712.

Co-authored-by: Kaity A <kaity@theallans.com.au>
Co-authored-by: Ken Allan <ken@norganna.com>
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9820
Co-authored-by: Kaity A <supakaity@noreply.codeberg.org>
Co-committed-by: Kaity A <supakaity@noreply.codeberg.org>
2023-04-07 14:25:22 +00:00

15 lines
380 B
TypeScript

export type Acct = {
username: string;
host: string | null;
};
export function parse(acct: string): Acct {
if (acct.startsWith('@')) acct = acct.substr(1);
const split = acct.split('@', 2);
return { username: split[0], host: split[1] || null };
}
export function toString(acct: Acct): string {
return acct.host == null ? acct.username : `${acct.username}@${acct.host}`;
}