tessl install tessl/npm-wrap-ansi@9.0.0Wordwrap a string with ANSI escape codes
Agent Success
Agent success rate when using this tile
100%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.04x
Baseline
Agent success rate without this tile
96%
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