|
960 | 960 | }
|
961 | 961 | },
|
962 | 962 |
|
| 963 | + /** |
| 964 | + * Run the matching between regular expression filters and string value |
| 965 | + * |
| 966 | + * @param filter {array} One or multiple filters to apply |
| 967 | + * @param val {string} Value to compare |
| 968 | + * @param inclusive {boolean} Inclusive (default) or exclusive |
| 969 | + * |
| 970 | + * @returns {boolean} |
| 971 | + */ |
| 972 | + filterMatching: function(filter, val, inclusive) { |
| 973 | + this.writeDebug('inclusiveFilter',arguments); |
| 974 | + inclusive = (typeof inclusive !== 'undefined') ? inclusive : true; |
| 975 | + var applyFilters; |
| 976 | + |
| 977 | + // Undefined check. |
| 978 | + if (typeof val === 'undefined') { |
| 979 | + return false; |
| 980 | + } |
| 981 | + |
| 982 | + // Modify the join depending on inclusive (AND) vs exclusive (OR). |
| 983 | + if ( true === inclusive ) { |
| 984 | + applyFilters = filter.join(''); |
| 985 | + } else { |
| 986 | + applyFilters = filter.join('|'); |
| 987 | + } |
| 988 | + |
| 989 | + if ((new RegExp(applyFilters, 'i').test(val.replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '')))) { |
| 990 | + return true; |
| 991 | + } |
| 992 | + |
| 993 | + return false; |
| 994 | + }, |
| 995 | + |
963 | 996 | /**
|
964 | 997 | * Filter the data with Regex
|
965 | 998 | *
|
|
969 | 1002 | */
|
970 | 1003 | filterData: function (data, filters) {
|
971 | 1004 | this.writeDebug('filterData',arguments);
|
972 |
| - var filterTest = true; |
| 1005 | + var filterTest = false; |
973 | 1006 |
|
974 | 1007 | for (var k in filters) {
|
975 | 1008 | if (filters.hasOwnProperty(k)) {
|
976 | 1009 |
|
977 | 1010 | // Exclusive filtering
|
978 | 1011 | if (this.settings.exclusiveFiltering === true || (this.settings.exclusiveTax !== null && Array.isArray(this.settings.exclusiveTax) && this.settings.exclusiveTax.indexOf(k) !== -1)) {
|
979 |
| - var filterTests = filters[k]; |
980 |
| - var exclusiveTest = []; |
981 |
| - |
982 |
| - if (typeof data[k] !== 'undefined') { |
983 |
| - for (var l = 0; l < filterTests.length; l++) { |
984 |
| - exclusiveTest[l] = new RegExp(filterTests[l], 'i').test(data[k].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '')); |
985 |
| - } |
986 |
| - } |
987 |
| - |
988 |
| - if (exclusiveTest.indexOf(true) === -1) { |
989 |
| - filterTest = false; |
990 |
| - } |
| 1012 | + filterTest = this.filterMatching(filters[k], data[k], false ); |
991 | 1013 | }
|
992 | 1014 | // Inclusive filtering
|
993 | 1015 | else {
|
994 |
| - if (typeof data[k] === 'undefined' || !(new RegExp(filters[k].join(''), 'i').test(data[k].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '')))) { |
995 |
| - filterTest = false; |
996 |
| - } |
| 1016 | + filterTest = this.filterMatching(filters[k], data[k]); |
997 | 1017 | }
|
998 | 1018 | }
|
999 | 1019 | }
|
1000 | 1020 |
|
1001 |
| - if (filterTest) { |
1002 |
| - return true; |
1003 |
| - } |
| 1021 | + return filterTest; |
1004 | 1022 | },
|
1005 | 1023 |
|
1006 | 1024 | /**
|
|
0 commit comments