@mcabreradev/filter
Version:
A powerful, SQL-like array filtering library for TypeScript and JavaScript with advanced pattern matching, MongoDB-style operators, deep object comparison, and zero dependencies
27 lines (26 loc) • 726 B
JavaScript
import { ref, computed } from 'vue';
import { filter } from '../../core';
export function useFilteredState(initialData = [], initialExpression = () => true, options) {
const data = ref(initialData);
const expression = ref(initialExpression);
const filtered = computed(() => {
if (!data.value || data.value.length === 0) {
return [];
}
try {
return filter(data.value, expression.value, options);
}
catch {
return [];
}
});
const isFiltering = computed(() => {
return filtered.value.length !== data.value.length;
});
return {
data,
expression,
filtered,
isFiltering,
};
}