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