Take the last word of text string and replace the space before it with a non-breaking space.
Created
May 11, 2022 18:32
-
-
Save megasmack/3bee875cb16ee5f88775642c4452c246 to your computer and use it in GitHub Desktop.
Remove orphans from text string
This file contains 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
/** | |
* Take the last word of text string and replace the space before it with a non-breaking space. | |
* @param {string} str | |
* @returns {string} | |
*/ | |
const deOrphan = (str) => { | |
return str ? str.replace(/ (\S*)$/, '\u00A0$1') : ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment