Function
wrapAt
(s: string, width: number)
Source from the content-addressed store, hash-verified
| 377 | } |
| 378 | |
| 379 | function wrapAt(s: string, width: number): string { |
| 380 | const words = s.split(' '); |
| 381 | const lines: string[] = []; |
| 382 | let cur = ''; |
| 383 | for (const w of words) { |
| 384 | if (cur.length === 0) { cur = w; continue; } |
| 385 | if (cur.length + 1 + w.length > width) { |
| 386 | lines.push(cur); |
| 387 | cur = w; |
| 388 | } else { |
| 389 | cur += ' ' + w; |
| 390 | } |
| 391 | } |
| 392 | if (cur) lines.push(cur); |
| 393 | return lines.join('\n'); |
| 394 | } |
Tested by
no test coverage detected