injectWordBreaks
Adds word-break opportunities to a string so it can wrap cleanly in narrow UI containers such as side panels or table cells.
Invisible zero-width spaces (\u200B) are inserted at meaningful
boundaries — camelCase splits, path separators, token edges — while
protected spans (URLs, emails, HTML) and atomic numeric values (-0.1%,
12ms, 1e-3) are never broken. The visible text content is unchanged.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
str | string | The string to process. |
Returns
Section titled “Returns”string — The string with word-break opportunities injected at meaningful
boundaries.
Examples
Section titled “Examples”camelCase identifier
Section titled “camelCase identifier”Inserts ZWS at each camelCase boundary so a long identifier can wrap in a narrow column.
Comma-separated tokens
Section titled “Comma-separated tokens”The comma attaches to the left token so a line never starts with a comma.
Atomic numeric value
Section titled “Atomic numeric value”Signed decimals and numbers with units (-0.1%, 12ms, -2.4E+6) are never split.
File path
Section titled “File path”Slashes become wrap points so a long path can break at each component.
URL is preserved intact
Section titled “URL is preserved intact”URLs are D0-protected spans — no ZWS is inserted inside or adjacent to them.
