greedy-wrap
A recursive greedy algorithm implementation for the word wrap process. It also correctly calculates the width of the words containing ANSI escape codes and astral symbols.
Install
$ npm install --save greedy-wrap
Usage
var greedyWrap = ; ; //=> Result: this is a dummy text that overflows the max width New lines must be considered ; //=> Result: Supercalifragilisticexpialidocious ; //=> Result: Supercalifragilisticexpialidocious //=> Result: this is a text with only shortwords //=> Result: Ayo Silver! 🦄🦄🦄
API
greedyWrap(input, [options])
input
Required
Type: string
options
width
Type: integer
Default: 34
The width of the text.
autoWidth
Type: boolean
Default: false
Override the width to the longest word length.
License
MIT © Danilo Sampaio