summaryrefslogtreecommitdiff
path: root/src/mfm/parse/elements/mention.ts
blob: eda60b530abc25246b0738b2f7aa4a886e1d11e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Mention
 */
import parseAcct from '../../../acct/parse';

export type TextElementMention = {
	type: 'mention'
	content: string
	username: string
	host: string
};

export default function(text: string) {
	const match = text.match(/^@[a-z0-9_]+(?:@[a-z0-9\.\-]+[a-z0-9])?/i);
	if (!match) return null;
	const mention = match[0];
	const { username, host } = parseAcct(mention.substr(1));
	return {
		type: 'mention',
		content: mention,
		username,
		host
	} as TextElementMention;
}