(text: string, width: number)
| 158 | } |
| 159 | |
| 160 | export function wrapText(text: string, width: number): string[] { |
| 161 | const lines: string[] = [] |
| 162 | let currentLine = '' |
| 163 | let currentWidth = 0 |
| 164 | |
| 165 | for (const { segment } of getGraphemeSegmenter().segment(text)) { |
| 166 | const segWidth = stringWidth(segment) |
| 167 | if (currentWidth + segWidth <= width) { |
| 168 | currentLine += segment |
| 169 | currentWidth += segWidth |
| 170 | } else { |
| 171 | if (currentLine) lines.push(currentLine) |
| 172 | currentLine = segment |
| 173 | currentWidth = segWidth |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (currentLine) lines.push(currentLine) |
| 178 | return lines |
| 179 | } |
| 180 |
nothing calls this directly
no test coverage detected