From 49af42e1bc759fda2aac5504eab845c6e2c93e9b Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:14:49 +0200 Subject: [PATCH] Improve string cleanup function Replace special character with a space and reduce multiple spaces to one --- src/lib/data/Strings.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/data/Strings.ts b/src/lib/data/Strings.ts index 8c5dfbfa..b06b4e63 100644 --- a/src/lib/data/Strings.ts +++ b/src/lib/data/Strings.ts @@ -8,4 +8,7 @@ export const baseCleanup = (str: string) => str.toLowerCase().trim(); -export const enhancedCleanup = (str: string): string => baseCleanup(str).replace(/[^a-zA-Z0-9]/g, ''); +export const enhancedCleanup = (str: string): string => + baseCleanup(str) + .replace(/[^a-zA-Z0-9\\s]+/g, ' ') + .trim();