# Text To Lines A class that splits text into sentences and provides a chainable API to accumulate text. ```typescript import { TextToLines } from "@triplef/helpers/text-to-lines"; ``` ## Supported Punctuation | Type | Punctuation | | ------------------------------- | ---------------------- | | Western | `.`, `?`, `!`, `...` | | CJK (Chinese, Japanese, Korean) | `。`, `?`, `!`, `……` | ## Constructor ```typescript new TextToLines(base: string | string[]): TextToLines ``` Initialize with a string or array of strings. ## Properties ### lines Returns the number of sentences currently accumulated. ```typescript const splitter = new TextToLines("Hello! How are you?"); splitter.lines; // 2 ``` ## Methods ### append Append more text or array of strings to the current sentences. Returns the same instance for chaining. ```typescript append(val: string | string[]): this ``` ### build Returns all accumulated sentences as an array of strings. ```typescript build(): string[] ``` Throws an error if no valid sentences exist. ## Examples ### Basic Usage ```typescript const splitter = new TextToLines("Hello world! How are you?"); splitter.lines; // 2 splitter.build(); // ["Hello world!", "How are you?"] ``` ### Chaining ```typescript const text = new TextToLines("First sentence.") .append("Second sentence?") .append("Third sentence!"); text.lines; // 3 text.build(); // ["First sentence.", "Second sentence?", "Third sentence!"] ``` ### Array Input ```typescript const text = new TextToLines(["Hello.", "How are you?"]); text.lines; // 2 text.build(); // ["Hello.", "How are you?"] ``` ### CJK Support ```typescript const text = new TextToLines("这是中文句子。还有另一个!"); text.lines; // 2 text.build(); // ["这是中文句子。", "还有一个!"] ``` ### Mixed Content ```typescript const text = new TextToLines("Hello world! 这是中文句子。How are you?") .append("もう一つの文。") .append(["And one more...", "Last one!"]); text.lines; // 5 text.build(); // ["Hello world!", "这是中文句子。", "How are you?", "もう一つの文。", "And one more...", "Last one!"] ```