Last active
November 2, 2020 13:51
-
-
Save ourmaninamsterdam/f191b8c36688bd31412111c599fab9a3 to your computer and use it in GitHub Desktop.
Forced text hyphenation
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
const hyphenateText = (text, breakpoint) => { | |
if (text.length > breakpoint) { | |
const words = text.split(' '); | |
return words.map((word) => { | |
if (word.length > breakpoint) { | |
const head = word.substr(0, breakpoint); | |
const tail = word.substr(breakpoint); | |
return `${head} -${tail}`; | |
} | |
return word; | |
}).join(' '); | |
} | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment