I was able to use .replace(/.{40}/g, '$&\n') to put a new line on every 40th character of a word from the input, but that cuts words in the middle. What is a wise choice in the situlation? Thanks!
I don't know the answer. That said, I'd hazard the following system might work:
Hope this might help!