Function cleanString

  • Cleans a string by removing leading/trailing whitespace from each line, removing empty lines, and joining the remaining lines with newline characters.

    Parameters

    • s: string

      The input string to be cleaned.

    Returns string

    A new string with cleaned content.

    const input = "  Hello  \n  World  \n\n  ";
    const cleaned = cleanString(input);
    console.log(cleaned); // Output: "Hello\nWorld"