25 lines
730 B
TypeScript
25 lines
730 B
TypeScript
export function parseMentions(text: string): string[] {
|
|
const mentionRegex = /@(\w+)/g
|
|
const matches = text.match(mentionRegex)
|
|
return matches ? matches.map(m => m.slice(1)) : []
|
|
}
|
|
|
|
export function linkifyMentions(text: string): string {
|
|
return text.replace(/@(\w+)/g, '<a href="/profile/$1" class="text-celo-green hover:underline">@$1</a>')
|
|
}
|
|
|
|
export function extractMentionedUsers(text: string): Array<{ username: string; position: number }> {
|
|
const mentionRegex = /@(\w+)/g
|
|
const mentions: Array<{ username: string; position: number }> = []
|
|
let match
|
|
|
|
while ((match = mentionRegex.exec(text)) !== null) {
|
|
mentions.push({
|
|
username: match[1],
|
|
position: match.index
|
|
})
|
|
}
|
|
|
|
return mentions
|
|
}
|