@metreeca/core - v0.9.22
    Preparing search index...

    Function clip

    • Clips a string to a code point budget.

      Shortens overlong content, replacing the last retained code point with a HORIZONTAL ELLIPSIS, so the result stays within the budget and reports visibly that content was dropped; the ellipsis is itself counted, so a budget of 1 leaves nothing but the ellipsis.

      Length is counted in code points rather than UTF-16 code units, so supplementary characters are kept whole and never split into isolated surrogates.

      Note

      Code points are not glyphs: a grapheme cluster the cut falls inside, an emoji sequence or a base character followed by combining marks among them, is split, and the retained prefix renders on its own.

      Parameters

      • string: string

        The string to clip

      • length: number = 0

        The maximum length of the result in code points; 0 or a negative value disables clipping; defaults to 0

      Returns string

      string unaltered if clipping is disabled or string counts no more than length code points; otherwise its first length-1 code points followed by an ellipsis