backend/src/lib/user-id.ts

13 lines
337 B
TypeScript

export const userId = (username: string, database: string) => {
const dbUrl = new URL(database);
return `@${username}>${dbUrl.hostname}`;
};
export const parseUserId = (id: string) => {
const matches = id.match(/^@([^>]+)>(.+)$/);
if (!matches) {
return null;
}
return { username: matches[1], hostname: matches[2] };
};