Skip to content

wrapText

wrapText(text, width?): string

Wraps text to fit within a specified width, breaking at word boundaries.

string

The text to wrap

number = 80

The maximum width in characters (default: 80)

string

The wrapped text with line breaks

const wrapped = wrapText("This is a very long text that needs to be wrapped to fit within an 80 character width.", 20);
console.log(wrapped);
// Output:
// This is a very
// long text that
// needs to be
// wrapped to fit
// within an 80
// character width.