John Cowen 99f102705d
ui: Fuzzy and Regex searching (#9424)
Moves search things around to match an interface that can be switched in and out of fuzzy searching using fuse.js. We add both fuzzy searching and regex based searching to the codebase here, but it is not yet compiled in.
2020-12-18 10:38:15 +00:00

16 lines
394 B
JavaScript

import PredicateSearch from './predicate';
export default class RegExpSearch extends PredicateSearch {
predicate(s) {
let regex;
try {
regex = new RegExp(s, 'i');
} catch (e) {
// Return a predicate that excludes everything; most likely due to an
// eager search of an incomplete regex
return () => false;
}
return item => regex.test(item);
}
}