mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 13:55:55 +00:00
99f102705d
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.
16 lines
394 B
JavaScript
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);
|
|
}
|
|
}
|