2020-08-23 08:50:11 +00:00
|
|
|
import components from "./Components";
|
|
|
|
|
|
|
|
export default class ComponentsFilter {
|
|
|
|
constructor() {
|
|
|
|
this.components = components;
|
|
|
|
}
|
|
|
|
|
|
|
|
all() {
|
|
|
|
return this.components;
|
|
|
|
}
|
|
|
|
|
|
|
|
whereCategory(category) {
|
2020-08-23 08:53:05 +00:00
|
|
|
if (this.isEmpty(category)) return this.components;
|
2020-08-23 08:50:11 +00:00
|
|
|
|
2020-08-23 08:53:05 +00:00
|
|
|
let pattern = new RegExp(`^${category}`, "i");
|
2020-08-23 08:50:11 +00:00
|
|
|
|
2020-08-23 08:53:05 +00:00
|
|
|
return this.components.filter((category) =>
|
|
|
|
category.name.match(pattern)
|
|
|
|
);
|
2020-08-23 08:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isEmpty(string) {
|
|
|
|
return string.length === 0;
|
|
|
|
}
|
|
|
|
}
|