(text: string, width: number)
| 41 | * Wrap `text` into multiple lines based on the `width`. |
| 42 | */ |
| 43 | export function wordWrap(text: string, width: number) { |
| 44 | let words = text.split(' ') |
| 45 | let lines = [] |
| 46 | |
| 47 | let line = '' |
| 48 | let lineLength = 0 |
| 49 | for (let word of words) { |
| 50 | let wordLength = stripVTControlCharacters(word).length |
| 51 | |
| 52 | if (lineLength + wordLength + 1 > width) { |
| 53 | lines.push(line) |
| 54 | line = '' |
| 55 | lineLength = 0 |
| 56 | } |
| 57 | |
| 58 | line += (lineLength ? ' ' : '') + word |
| 59 | lineLength += wordLength + (lineLength ? 1 : 0) |
| 60 | } |
| 61 | |
| 62 | if (lineLength) { |
| 63 | lines.push(line) |
| 64 | } |
| 65 | |
| 66 | return lines |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Format a duration in nanoseconds to a more human readable format. |
no outgoing calls
no test coverage detected