Skip to content

trimToWidth

trimToWidth(text, maxWidth, widthOf): string

Defined in: labels/measure.ts:65

Trim text to at most maxWidth px with a trailing ELLIPSIS (#496). widthOf measures a string’s px width. A text that already fits comes back as the same string. Otherwise it is the longest prefix that fits together with the ellipsis (binary search: O(log length) measurements), cut on a whole character (never between the halves of a surrogate pair) and without whitespace before the ellipsis. When not even one character fits it is the ellipsis alone.

string

number

(s) => number

string