multi-filter-array
v1.0.4
Published
A simple array Filter to run multiple conditions against an item
Downloads
18
Readme
multi-array-filter
Filter an Array using multiple predicates
It takes 2 mandatory arguments and 2 optional argument.
- First parameter is the input array.
- Second argument is array of predicates which needs to validated against the array.
- Third argument is optional boolean which indicates whether an item should pass all predicates or atleast one predicate. true validates that all predicates are satisfied and false validates atleast one predicate is satisfied
- Fourth Argument is optional comparator function to sort the resultant array
import filterArray from 'multi-filter-array'
const addressListArray = [{
name: 'TestUser1',
email: '[email protected]',
age: 25,
address: 'TestCountry1'
},
{
name: 'TestUser2',
email: '[email protected]',
age: 35,
address: 'TestCountry2'
},
{
name: 'TestUser3',
email: '[email protected]',
age: 28,
address: 'TestCountry1'
}
];
filterArray(addressListArray, [person => person.address == 'TestCountry1', person => person.name == 'TestUser3'])