Last active
November 18, 2021 15:11
-
-
Save Richienb/6b9a05b4bfe4d57530559f58a4eecf0d to your computer and use it in GitHub Desktop.
Wrap words
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 string = ``; | |
const wrapWords = (string, width) => string.replace(new RegExp(`(?![^\\n]{1,${width}}$)([^\\n]{1,${width}})\\s`, 'g'), '$1\n'); | |
console.log(string.split('\n').map(value => wrapWords(value, 80)).join('\n\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment