Wordwrap a string with ANSI escape codes
Overall
score
100%
Build a text wrapping utility that properly handles edge cases involving whitespace-only input strings. The utility should support configurable whitespace preservation behavior.
The utility should wrap text to a specified column width and handle whitespace-only strings correctly based on configuration:
Implement a text wrapping function that:
Support a trim configuration option that controls whitespace handling:
The utility must correctly handle whitespace-only input strings:
" " (three spaces) at width 10 with trim enabled, returns an empty string @test" " (five spaces) at width 10 with trim disabled, returns the spaces wrapped according to column width @test"\t\t" (two tabs) at width 10 with trim enabled, returns an empty string @test" hello " at width 10 with trim enabled, removes leading and trailing spaces but preserves the word @test@generates
/**
* Wraps text to fit within specified column width
*
* @param {string} text - The text to wrap
* @param {number} columns - Maximum column width
* @param {Object} options - Configuration options
* @param {boolean} options.trim - Remove leading/trailing whitespace from wrapped lines (default: true)
* @returns {string} The wrapped text
*/
function wrapText(text, columns, options) {
// Implementation here
}
module.exports = { wrapText };Provides text wrapping support with ANSI escape code handling.
@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