Extending filter

import {Clause, Filters, getDefaultFilters, Filter} from "@anthonykgross/extensible-array-filter";

class MyFilter extends Filter {
assert = (clause: Clause<any>, item: any) => {
let value = item[clause.field]
return typeof value === 'string' && new RegExp(clause.value, "gi").test(value)
}
}

Add yours to the default one.

let filters: Filters = {
...getDefaultFilters,
'my-operator': MyFilter,
}

or only use yours.

let filters: Filters = {
'my-operator': MyFilter,
}
interface Row {
id: number;
name: string;
}

const rows: Row[] = [
{ id: 1, name: 'Example 1'},
{ id: 2, name: 'Example 2'},
{ id: 3, name: 'Example 3'},
];
rows.where(
[
{ field: 'name', operator: 'my-operator', value: '1' },
],
filters
);

// Expected output: [ { id: 1, name: 'Example 1' } ]