Last active
February 2, 2023 17:02
-
-
Save T99/cc73b268c7ed7e4f9ee451b835b85cee to your computer and use it in GitHub Desktop.
A TypeScript function that returns a modified version of the input string, having collapsed all horizontal whitespace down to single space characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a modified version of the input string, having collapsed all | |
* horizontal whitespace down to single space characters. | |
* | |
* @param input {string} The string that should be modified to have it's | |
* whitespaces collapsed. | |
* @returns {string} A modified version of the input string, having collapsed | |
* all horizontal whitespace down to single space characters. | |
*/ | |
export function collapseWhitespace(input: string): string { | |
return input.replace(/[^\S\r\n]+/gui, " "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment