• Normalizes a string by removing special characters and collapsing whitespace. Optionally converts to lowercase based on case sensitivity setting.

    Parameters

    • text: string

      String to normalize.

    • isCaseSensitive: boolean = false

      Whether to preserve case (default: false).

    Returns string

    Normalized string with special characters and extra whitespace removed.

    export function normalizeString(text: string, isCaseSensitive = false): string {
    if (!text) return "";

    // Replace special characters and normalize spacing
    const replaced = text
    .replaceAll(/[^\w\s]/gi, " ") // Replace special chars with space
    .replaceAll(/\s+/g, " ") // Collapse multiple spaces
    .trim();

    return isCaseSensitive ? replaced : replaced.toLowerCase();
    }