This function receives a text and a column width and returns the same text with line breaks every time the number of characters exceeds the column width. If before reaching the column width the function finds a space, it will separate the words by the space.
Example
text = '', columnWidth = 5 // => ''
text = 'hello', columnWidth = 5 // => 'hello'
text = 'helloworld', columnWidth = 5 // => 'hello\nworld'
text = 'helloworld!', columnWidth = 5 // => 'hello\nworld\n!'
text = 'hello world!', columnWidth = 6 // => 'hello\nworld!'
Install
npm install
Run test
npm test