Improve string cleanup function

Replace special character with a space and reduce multiple spaces to one
This commit is contained in:
schroda
2024-08-14 15:14:49 +02:00
parent d2f68041cb
commit 49af42e1bc

View File

@@ -8,4 +8,7 @@
export const baseCleanup = (str: string) => str.toLowerCase().trim(); 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();