data/edge5/video/v2/+
This commit is contained in:
38
app/src/helpers/topic-match.ts
Normal file
38
app/src/helpers/topic-match.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export function topicMatchesFilter(filter: string, topic: string): boolean {
|
||||
const filterParts = filter.split('/')
|
||||
const topicParts = topic.split('/')
|
||||
|
||||
let fi = 0
|
||||
let ti = 0
|
||||
|
||||
while (fi < filterParts.length) {
|
||||
const segment = filterParts[fi]
|
||||
|
||||
if (segment === '#') {
|
||||
return fi === filterParts.length - 1
|
||||
}
|
||||
|
||||
if (ti >= topicParts.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (segment === '+') {
|
||||
fi++
|
||||
ti++
|
||||
continue
|
||||
}
|
||||
|
||||
if (segment !== topicParts[ti]) {
|
||||
return false
|
||||
}
|
||||
|
||||
fi++
|
||||
ti++
|
||||
}
|
||||
|
||||
return ti === topicParts.length
|
||||
}
|
||||
|
||||
export function lastTopicSegment(topic: string): string {
|
||||
return topic.split('/').at(-1) ?? ''
|
||||
}
|
||||
Reference in New Issue
Block a user