(maxLength, input)
| 250 | |
| 251 | // Wrap on word boundary |
| 252 | function wordWrap(maxLength, input) { |
| 253 | let lines = []; |
| 254 | let split = input.split(/(\s+)/g); |
| 255 | let line = []; |
| 256 | let lineLength = 0; |
| 257 | let whitespace; |
| 258 | for (let i = 0; i < split.length; i += 2) { |
| 259 | let word = split[i]; |
| 260 | let newLength = lineLength + strlen(word); |
| 261 | if (lineLength > 0 && whitespace) { |
| 262 | newLength += whitespace.length; |
| 263 | } |
| 264 | if (newLength > maxLength) { |
| 265 | if (lineLength !== 0) { |
| 266 | lines.push(line.join('')); |
| 267 | } |
| 268 | line = [word]; |
| 269 | lineLength = strlen(word); |
| 270 | } else { |
| 271 | line.push(whitespace || '', word); |
| 272 | lineLength = newLength; |
| 273 | } |
| 274 | whitespace = split[i + 1]; |
| 275 | } |
| 276 | if (lineLength) { |
| 277 | lines.push(line.join('')); |
| 278 | } |
| 279 | return lines; |
| 280 | } |
| 281 | |
| 282 | // Wrap text (ignoring word boundaries) |
| 283 | function textWrap(maxLength, input) { |
no test coverage detected
searching dependent graphs…