Skip to content

Instantly share code, notes, and snippets.

@bretmorris
Last active April 18, 2020 00:10
Show Gist options
  • Save bretmorris/b28e5509a82d60a05cccc0f8f851eed2 to your computer and use it in GitHub Desktop.
Save bretmorris/b28e5509a82d60a05cccc0f8f851eed2 to your computer and use it in GitHub Desktop.
Very small (and stupid) function for removing widows using a non-breaking-space on a string (client's hate widows)
// NOTE: Can't handle HTML yet
// USE: noWidows('My copy goes here')
// RESULT: My copy goes here
const noWidows = (copy) => copy.replace(/(\s)+(\S*)$/, (match, p1, p2) => ` ${p2}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment