(value: string, width: number)
| 275 | } |
| 276 | |
| 277 | function wrapPlainText(value: string, width: number) { |
| 278 | if (!value) return [""] |
| 279 | const words = value.split(" ") |
| 280 | const lines: string[] = [] |
| 281 | let current = "" |
| 282 | for (const word of words) { |
| 283 | if (!word) continue |
| 284 | if (word.length > width) { |
| 285 | if (current) { |
| 286 | lines.push(current) |
| 287 | current = "" |
| 288 | } |
| 289 | let start = 0 |
| 290 | while (start < word.length) { |
| 291 | lines.push(word.slice(start, start + width)) |
| 292 | start += width |
| 293 | } |
| 294 | continue |
| 295 | } |
| 296 | const attempt = current ? `${current} ${word}` : word |
| 297 | if (attempt.length <= width) { |
| 298 | current = attempt |
| 299 | } else { |
| 300 | if (current) lines.push(current) |
| 301 | current = word |
| 302 | } |
| 303 | } |
| 304 | if (current) lines.push(current) |
| 305 | if (!lines.length) lines.push("") |
| 306 | return lines |
| 307 | } |
no test coverage detected