@jiminp/tooltool
    Preparing search index...

    Function chunkText

    • Splits text into chunks with a maximum length, preferring to split at separators.

      Parameters

      • text: string

        The text to split.

      • max_length: number

        Maximum chunk length (positive safe integer).

      • separators: string[] = ...

        Split points in order of preference (default: ['\n', ' ', '.']).

      Returns string[]

      Array of text chunks.

      If max_length is not a positive safe integer.

      • Separators are only considered in the latter half of each chunk to avoid tiny chunks.
      • Each chunk is trimmed (leading/trailing whitespace removed) before being added to results.
      • Empty chunks (after trimming) are skipped.
      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']