merakiui/src/models/ComponentsFilter.js

27 lines
499 B
JavaScript
Raw Normal View History

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) {
if(this.isEmpty(category)) return this.components;
let pattern = new RegExp(`^${category}`, 'i');
return this.components.filter(category => category.name.match(pattern));
}
isEmpty(string) {
return string.length === 0;
}
}