2022-01-21 23:21:46 +00:00
|
|
|
export function parseTags(text: string) {
|
|
|
|
const regex = /(?:^|\s)(?:[#][a-z0-9_]+)/gi
|
|
|
|
const matches = (text.match(regex) || []).map((match) =>
|
|
|
|
match.trim().substring(1)
|
|
|
|
)
|
|
|
|
const tagSet = new Set(matches)
|
|
|
|
const uniqueTags: string[] = []
|
|
|
|
tagSet.forEach((tag) => uniqueTags.push(tag))
|
|
|
|
return uniqueTags
|
|
|
|
}
|
|
|
|
|
|
|
|
export function parseWordsAsTags(text: string) {
|
2022-01-22 00:07:11 +00:00
|
|
|
const regex = /(?:^|\s)(?:#?[a-z0-9_]+)/gi
|
2022-01-21 23:21:46 +00:00
|
|
|
const matches = (text.match(regex) || [])
|
2022-01-22 00:07:11 +00:00
|
|
|
.map((match) => match.replace('#', '').trim())
|
2022-01-21 23:21:46 +00:00
|
|
|
.filter((tag) => tag)
|
|
|
|
const tagSet = new Set(matches)
|
|
|
|
const uniqueTags: string[] = []
|
|
|
|
tagSet.forEach((tag) => uniqueTags.push(tag))
|
|
|
|
return uniqueTags
|
|
|
|
}
|