function wordWrap(s, { maxLength = 20 } = {}) {
const words = s.split(/\s+/);
const lines = [words[0]];
for (const word of words.slice(1)) {
if (lines[lines.length - 1].length + word.length < maxLength) {
if (lines.length > 0) lines[lines.length - 1] += " ";
lines[lines.length - 1] += word;
} else {
lines.push(word);
}
}
return lines.join("\n");
}