Remove orphans from text string
Take the last word of text string and replace the space before it with a non-breaking space.
/** | |
* 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') : ''; | |
} |