src/services/layout.mjs
BeforeProposed
+14−2
44export function wrap(text, width) {
55 integer(width, 'width', 1);
66 if (width > 120) throw new InputError('width must be <= 120');
7 // Implement wrapping for the editor and export callers.
8 return [text];
7 const lines = [];
8 for (const paragraph of text.split(/\r?\n/)) {
9 let line = '';
10 for (const word of paragraph.trim().split(/\s+/).filter(Boolean)) {
11 if (line && [...`${line} ${word}`].length > width) {
12 lines.push(line);
13 line = word;
14 } else {
15 line = line ? `${line} ${word}` : word;
16 }
17 }
18 lines.push(line);
19 }
20 return lines;
921}
1022
1123export function layout(document, command) {