Wordwrap a string with ANSI escape codes
Overall
score
100%
Build a text formatting utility that wraps text to fit within a specified width while providing flexible whitespace handling for different display contexts.
Your utility should format text blocks to fit within terminal constraints while offering control over how whitespace is handled on wrapped lines.
Implement a function formatText(text, width, preserveWhitespace) that:
preserveWhitespace is false (default), removes leading and trailing spaces from wrapped lines for clean outputpreserveWhitespace is true, maintains all whitespace exactly as provided in the inputThe formatter should demonstrate these behaviors:
@generates
/**
* Formats text to fit within specified width with whitespace control
*
* @param {string} text - The text to format
* @param {number} width - Maximum width in columns
* @param {boolean} preserveWhitespace - If true, preserve all whitespace; if false, trim wrapped lines
* @returns {string} Formatted text
*/
function formatText(text, width, preserveWhitespace = false) {
// Implementation here
}
module.exports = { formatText };Provides text wrapping with ANSI code support and whitespace control.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-wrap-ansidocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10