From af5e7f7cdefab4cdb1e51366e6e5c363ce1dd855 Mon Sep 17 00:00:00 2001 From: zhzluke96 Date: Fri, 27 Dec 2024 01:25:02 +0800 Subject: [PATCH] feat: fuzzyMatch ignore case --- src/App.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c1e88af..2a3e84d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -32,7 +32,11 @@ function escapeRegExp(str: string) { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } -function fuzzyMatch(pattern: string, str: string) { +function fuzzyMatch(pattern: string, text: string) { + // NOTE: ignore case + pattern = pattern.toLowerCase(); + text = text.toLowerCase(); + pattern = ".*" + pattern @@ -42,7 +46,7 @@ function fuzzyMatch(pattern: string, str: string) { .map((l: string) => `${escapeRegExp(l)}.*`) .join(""); const re = new RegExp(pattern); - return re.test(str); + return re.test(text); } // 通用类型定义