platform-bible-utils
    Preparing search index...

    Function truncateToCopyLimit

    • Shortens text to at most copyLimit UTF-16 code units without splitting a grapheme cluster: a character outside the Basic Multilingual Plane, a base letter with its combining marks, or a conjunct. Clusters come from unicode-segmenter, as for the rest of this package. The result is the longest start of text that fits and ends at a cluster boundary, so it can be shorter than copyLimit.

      Segmentation contract: cuts only at grapheme-cluster boundaries as unicode-segmenter finds them, measured in UTF-16 code units, the same contract EditorOptions.copyLimit follows, so a copy cut here and one the editor cuts end at the same place.

      Parameters

      • text: string

        The text to shorten.

      • copyLimit: undefined | number

        The most UTF-16 code units the result may have, or undefined for no limit.

      Returns string

      text itself when it fits or there is no limit, otherwise its longest start that fits.