mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-24 14:04:19 +00:00
✨ Add some Filters
This commit is contained in:
parent
eebedebe5e
commit
98bfb71d00
1 changed files with 62 additions and 0 deletions
62
nest_frontend/utils/Filter.js
Normal file
62
nest_frontend/utils/Filter.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
export class Filter {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
exec(tweet) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export class ContainsFilter extends Filter {
|
||||
word
|
||||
|
||||
constructor(word) {
|
||||
super()
|
||||
this.word = word.toLowerCase().trim()
|
||||
}
|
||||
|
||||
exec(tweet) {
|
||||
return tweet.content?.toLowerCase().includes(this.word)
|
||||
}
|
||||
}
|
||||
|
||||
export class UserFilter extends Filter {
|
||||
user
|
||||
|
||||
constructor(user) {
|
||||
super()
|
||||
this.user = user.toLowerCase().trim().replace(/^@/, "")
|
||||
}
|
||||
|
||||
exec(tweet) {
|
||||
return tweet.poster.toLowerCase() === this.user
|
||||
}
|
||||
}
|
||||
|
||||
export class HasLocationFilter extends Filter {
|
||||
hasLocation
|
||||
|
||||
constructor(hasLocation) {
|
||||
super()
|
||||
this.hasLocation = hasLocation
|
||||
}
|
||||
|
||||
exec(tweet) {
|
||||
return (tweet["location"] !== null) === this.hasLocation
|
||||
}
|
||||
}
|
||||
|
||||
export class HasPlaceFilter extends Filter {
|
||||
hasPlace
|
||||
|
||||
constructor(hasPlace) {
|
||||
super()
|
||||
this.hasPlace = hasPlace
|
||||
}
|
||||
|
||||
exec(tweet) {
|
||||
return (tweet["place"] !== null) === this.hasPlace
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue