Skip to content

Function.wrapText

github-actions[bot] edited this page Nov 18, 2026 · 13 revisions

umt / wrapText

Function: wrapText()

wrapText(string_, width): string

Defined in: String/wrapText.ts:15

Wraps text to lines of at most width characters (UTF-16 code units) at word boundaries. Existing line breaks are kept and each line is wrapped on its own. Words are separated by spaces, tabs, carriage returns, form feeds and vertical tabs, and a word longer than width is placed on its own line without being broken.

Parameters

string_

string

The text to wrap

width

number

The maximum line width

Returns

string

The wrapped text joined with "\n"

Example

wrapText("The quick brown fox", 10); // "The quick\nbrown fox"
wrapText("a extraordinary b", 5); // "a\nextraordinary\nb"

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally