Skip to content

Instantly share code, notes, and snippets.

@ourmaninamsterdam
Last active November 2, 2020 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourmaninamsterdam/f191b8c36688bd31412111c599fab9a3 to your computer and use it in GitHub Desktop.
Save ourmaninamsterdam/f191b8c36688bd31412111c599fab9a3 to your computer and use it in GitHub Desktop.
Forced text hyphenation
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