Simple but fast data filter.
-
search single key only.
import { filterData, SearchType } from 'filter-data';
const searchConditions = [
{
key: 'firstName',
value: 'dan',
type: SearchType.LK,
},
{
key: 'age',
value: 20,
type: SearchType.LT,
},
];
const result = filterData(data, searchConditions);
<!-- [
{ firstName: 'Daniel', age: 14 },
{ firstName: 'Dan', age: 18 },
] -->
-
search multiple keys.
import { filterData, SearchType } from 'filter-data';
const searchConditions = [
{
key: ['firstName', 'lastName'],
value: 'dan',
type: SearchType.LK,
},
{
key: 'age',
value: 20,
type: SearchType.LT,
},
];
const result = filterData(data, searchConditions);
<!-- [
{ firstName: 'Daniel', lastName: 'Johnson', age: 13 },
{ firstName: 'Jack', lastName: 'Danny', age: 19 },
] -->
-
caseSensitive.
import { filterData, SearchType } from 'filter-data';
const searchConditions = [
{
key: 'firstName',
value: 'dan',
type: SearchType.LK,
},
];
const result = filterData(data, searchConditions, { caseSensitive: true });
<!-- [
{ firstName: 'Jordan', age: 17 },
] -->
-
offset & limit.
import { filterData, SearchType } from 'filter-data';
const searchConditions = [
{
key: 'firstName',
value: 'dan',
type: SearchType.LK,
},
];
const result = filterData(data, searchConditions, { caseSensitive: true, offset: 10, limit: 10 });
<!-- [
{ firstName: 'Jordan', age: 17 },
.
.
.
max 10 records
] -->
-
search nested object.
import { filterData, SearchType } from 'filter-data';
const searchConditions = [
{
key: 'father.firstName',
value: 'dan',
type: SearchType.EQ,
},
];
const result = filterData(data, searchConditions);
<!-- [
{ firstName: 'Jordan', age: 17, father: { firstName: 'dan', age: 50 } },
] -->