UNPKG

@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) 747 B
import { computed, unref } from 'vue'; import { filter } from '../../core'; export function useFilter(data, expression, options) { const filtered = computed(() => { const dataValue = unref(data); const expressionValue = unref(expression); const optionsValue = unref(options); if (!dataValue || dataValue.length === 0) { return []; } try { return filter(dataValue, expressionValue, optionsValue); } catch { return []; } }); const isFiltering = computed(() => { const dataValue = unref(data); return filtered.value.length !== dataValue.length; }); return { filtered, isFiltering, }; }