mirror of
https://github.com/KevinMidboe/planetposen-backend.git
synced 2025-10-29 16:30:13 +00:00
35 lines
703 B
JavaScript
35 lines
703 B
JavaScript
class Filters {
|
|
constructor(value) {
|
|
this.value = value;
|
|
this.delimiter = "|";
|
|
}
|
|
|
|
get filters() {
|
|
return this.value.split(this.delimiter).slice(0, -1);
|
|
}
|
|
|
|
isEmpty() {
|
|
return !this.hasValidType() || this.value.length === 0;
|
|
}
|
|
|
|
has(filter) {
|
|
return this.filters.includes(filter);
|
|
}
|
|
|
|
hasValidType() {
|
|
return typeof this.value === "string";
|
|
}
|
|
|
|
removeFiltersFromValue() {
|
|
if (this.hasValidType() === false) {
|
|
return this.value;
|
|
}
|
|
|
|
let filtersCombined = this.filters.join(this.delimiter);
|
|
filtersCombined += this.filters.length >= 1 ? this.delimiter : "";
|
|
return this.value.replace(filtersCombined, "");
|
|
}
|
|
}
|
|
|
|
module.exports = Filters;
|