From 112bd38d7f83a03789d638f39a71c56aa517691b Mon Sep 17 00:00:00 2001 From: Mercedes Rey Date: Wed, 24 Jul 2019 14:53:43 +0100 Subject: [PATCH] Add the ability to search with a global regex --- src/util.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util.js b/src/util.js index 5bf94fe..32f46e3 100644 --- a/src/util.js +++ b/src/util.js @@ -39,7 +39,7 @@ export function getValuesForKey (key, item) { return results.filter(r => typeof r === 'string' || typeof r === 'number') } -export function searchStrings (strings, term, {caseSensitive, fuzzy, sortResults, exactMatch} = {}) { +export function searchStrings (strings, term, {caseSensitive, fuzzy, sortResults, exactMatch, regexMatch} = {}) { strings = strings.map(e => e.toString()) try { @@ -60,7 +60,9 @@ export function searchStrings (strings, term, {caseSensitive, fuzzy, sortResults } if (exactMatch) { term = new RegExp('^' + term + '$', 'i') - } + } else if (regexMatch) { + term = new RegExp(term, 'i') + } if (value && value.search(term) !== -1) { return true }