Skip to main content
The text module provides pure-JS text processing utilities, with no external dependencies.

splitText

Split text into chunks using a recursive character splitting strategy. The splitter tries separators in order, splits on the first one found, merges small pieces back up to chunkSize, maintains chunkOverlap between consecutive chunks, and recurses with finer separators for pieces still too large.
Returns an array of { content, size } objects:

Split with custom separators (e.g. Markdown headings)

Iterate over chunks