Files
twenty/packages/twenty-front/src/utils/normalizeSearchText.ts
T
Saurav Jain 8ba1dc1d94 Added a util helper to remove accent and case to improve search logic (#14533)
# [WIP] Make Local Search Non-Accent-Sensitive

fixes(#14468)

---

**Description:**  
This PR adds accent- and case-insensitive search for the
**SettingsWorkspaceMembers** component’s local search. It ensures that
searching for names or emails works correctly even if the user types
letters without accents.

**Implementation:**  
- Added a helper util: `removeAccentsAndCase(text: string)`  
- This util:
  - Normalizes text to NFD form
  - Removes diacritics (accents)
  - Converts text to lowercase
- Replaced current `.includes(searchFilter)` logic with a normalized
comparison:


---

### Video ->

[Screencast from 2025-09-16
16-42-50.webm](https://github.com/user-attachments/assets/7035906c-9c5d-414d-81e5-74e53803628a)


---

Opening a draft pr for initial strategy review before extending it to
other components.

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
2025-09-19 17:03:43 +02:00

18 lines
443 B
TypeScript

export const normalizeSearchText = (
text: string | null | undefined,
): string => {
if (!text) return '';
return text
.normalize('NFD')
.replace(/\p{Diacritic}/gu, '')
.replace(/[øØ]/g, 'o')
.replace(/[åÅ]/g, 'a')
.replace(/[æÆ]/g, 'ae')
.replace(/[ßẞ]/g, 'ss')
.replace(/[ðÐ]/g, 'd')
.replace(/[þÞ]/g, 'th')
.replace(/[łŁ]/g, 'l')
.replace(/[œŒ]/g, 'oe')
.toLowerCase();
};