@jiminp/tooltool
    Preparing search index...

    Function chunkText

    • Splits text into trimmed, non-empty chunks, preferring separators over forced splits.

      Parameters

      • text: string

        The text to split.

      • max_length: number

        Maximum chunk length in UTF-16 code units (positive safe integer).

      • separators: string[] = ...

        Literal split points in priority order (default: ['\n', ' ', '.']).

      Returns string[]

      The trimmed, non-empty chunks.

      If max_length is not a positive safe integer.

      • For text exceeding the limit, uses the rightmost eligible occurrence of the first matching separator: its start must be at least Math.floor(max_length / 2) and its end within the limit. Separators stay in the preceding chunk unless trimmed.
      • Trims every chunk and skips empty chunks.
      • Never splits surrogate pairs; a non-BMP code point with max_length = 1 is the sole length-limit exception (2 units). Unpaired surrogates are preserved.
      • Code-point safety is not grapheme safety: combining marks and ZWJ sequences may split.
      chunkText('hello world', 5);     // ['hello', 'world']
      chunkText('hello world', 7); // ['hello', 'world']
      chunkText('abcdefghij', 5); // ['abcde', 'fghij']
      chunkText('a b c d e', 4); // ['a b', 'c d', 'e']