From 6db4154913c11a1b009d2b46eb5ef9676499ca3c Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Wed, 18 Jun 2025 11:55:11 -0300 Subject: [PATCH] feat: enable searching without special characters --- src/index.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index a4b3df9..64b3d4a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -435,13 +435,27 @@ const setupEventListeners = () => { }); } +const getCleanName = (foodName: string): string => { + const newName = foodName + .replace(/á/g, 'a') + .replace(/ã/g, 'a') + .replace(/â/g, 'a') + .replace(/ê/g, 'e') + .replace(/é/g, 'e') + .replace(/ó/g, 'o') + .replace(/ú/g, 'u') + .replace(/ç/g, 'c'); + return newName.toLowerCase(); +} + // Perform search function performSearch(query: string) { // Simulate API call - replace with your actual database search - const results: FoodItem[] = foodDatabase.filter(food => - food.name.toLowerCase().includes(query.toLowerCase()) || - food.info.category.toLowerCase().includes(query.toLowerCase()) - ).slice(0, 5); // Limit to 5 results + const results: FoodItem[] = foodDatabase.filter(food => { + const cleanName = getCleanName(food.name); + const category = food.info.category.toLowerCase(); + return cleanName.includes(query.toLowerCase()) || category.includes(query.toLowerCase()) + }).slice(0, 5); // Limit to 5 results currentResults = results; displaySearchResults(results);