MCPcopy Index your code
hub / github.com/cli-table/cli-table3 / wordWrap

Function wordWrap

src/utils.js:252–280  ·  view source on GitHub ↗
(maxLength, input)

Source from the content-addressed store, hash-verified

250
251// Wrap on word boundary
252function 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)
283function textWrap(maxLength, input) {

Callers 1

utils-test.jsFile · 0.85

Calls 1

strlenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…