|
|
|
@ -53,7 +53,7 @@ export const createFilter = (term, keys, options = {}) => {
|
|
|
|
|
return strings.some(value => {
|
|
|
|
|
try {
|
|
|
|
|
if (!caseSensitive) {
|
|
|
|
|
value = value.toLowerCase();
|
|
|
|
|
value = value?.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
if (exactMatch) {
|
|
|
|
|
term = new RegExp(`^${term}$`, 'i');
|
|
|
|
@ -75,31 +75,31 @@ export const createFilter = (term, keys, options = {}) => {
|
|
|
|
|
if (term === '') { return true; }
|
|
|
|
|
|
|
|
|
|
if (!options.caseSensitive) {
|
|
|
|
|
term = term.toLowerCase();
|
|
|
|
|
term = term?.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const terms = term.split(' ');
|
|
|
|
|
const terms = term?.split(' ');
|
|
|
|
|
|
|
|
|
|
if (!keys) {
|
|
|
|
|
return terms.every(term => searchStrings([ item ], term, options));
|
|
|
|
|
return terms?.every(term => searchStrings([ item ], term, options));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof keys === 'string') {
|
|
|
|
|
keys = [ keys ]
|
|
|
|
|
keys = [ keys ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return terms.every(term => {
|
|
|
|
|
return terms?.every(term => {
|
|
|
|
|
// allow search in specific fields with the syntax `field:search`
|
|
|
|
|
let currentKeys;
|
|
|
|
|
if (term.indexOf(':') !== -1) {
|
|
|
|
|
const searchedField = term.split(':')[0];
|
|
|
|
|
[ , term ] = term.split(':');
|
|
|
|
|
currentKeys = keys.filter(key => key.toLowerCase().indexOf(searchedField) > -1);
|
|
|
|
|
if (term?.indexOf(':') !== -1) {
|
|
|
|
|
const searchedField = term?.split(':')[0];
|
|
|
|
|
[ , term ] = term?.split(':');
|
|
|
|
|
currentKeys = keys?.filter(key => key.toLowerCase()?.indexOf(searchedField) > -1);
|
|
|
|
|
} else {
|
|
|
|
|
currentKeys = keys;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return currentKeys.some(key => {
|
|
|
|
|
return currentKeys?.some(key => {
|
|
|
|
|
const values = getValuesForKey(key, item);
|
|
|
|
|
return searchStrings(values, term, options);
|
|
|
|
|
});
|
|
|
|
|