### Initialize and Use TextHyphen Source: https://github.com/lunarisapp/text-tools/blob/main/packages/hyphen/README.md Demonstrates how to initialize TextHyphen with custom or default language and hyphenation rules. Shows examples of getting hyphenation positions, wrapping words, finding variants, and inserting hyphens. ```typescript import { TextHyphen } from '@lunarisapp/hyphen'; const textHyphen = new TextHyphen({ lang: 'en_US', // optional, en_US by default left: 2, // optional, 2 by default right: 2, // optional, 2 by default }); // Gets the textHyphenation points for a word. // Result: [2, 6] textHyphen.positions('hyphenation'); // Wraps a word with hyphens at the given positions. // Result: 'hy-phenation' textHyphen.wrap('hy-phenation', 3); // Gets the hyphenation variants for a word. // Result: [['hy', 'phenation'], ['hyphen', 'ation']] textHyphen.variants('hyphenation'); // Inserts hyphens in all possible positions. // Result: 'hy-phen-ation' textHyphen.inserted('hyphenation'); ``` -------------------------------- ### Install @lunarisapp/readability Source: https://github.com/lunarisapp/text-tools/blob/main/packages/readability/README.md Install the library using npm. This command is used for both browser and Node.js environments. ```bash npm install @lunarisapp/readability ``` -------------------------------- ### Install Lunaris Language Package Source: https://github.com/lunarisapp/text-tools/blob/main/packages/language/README.md Install the @lunarisapp/language package using npm. ```bash npm install @lunarisapp/language ``` -------------------------------- ### Install @lunarisapp/cmudict Source: https://github.com/lunarisapp/text-tools/blob/main/packages/cmudict/README.md Install the package using npm. This command is used for both Node.js and browser projects. ```bash npm install @lunarisapp/cmudict ``` -------------------------------- ### Install Lunaris Hyphen Source: https://github.com/lunarisapp/text-tools/blob/main/packages/hyphen/README.md Install the library using npm. This command is used for both browser and Node.js environments. ```bash npm install @lunarisapp/hyphen ``` -------------------------------- ### Install Lunaris Stats Source: https://github.com/lunarisapp/text-tools/blob/main/packages/stats/README.md Install the library using npm. This command adds the @lunarisapp/stats package to your project dependencies. ```bash npm install @lunarisapp/stats ``` -------------------------------- ### Initialize CMUdict Interfaces Source: https://github.com/lunarisapp/text-tools/blob/main/packages/cmudict/README.md Import and initialize the CMUdict interfaces for accessing pronunciation data, phonetic symbols, and more. Ensure the import path is correct for your project setup. ```typescript import cmudict from '@lunarisapp/cmudict'; const cmuDict = cmudict.dict(); const cmuPhones = cmudict.phones(); const cmuVP = cmudict.vp(); const cmuSymbols = cmudict.symbols(); ``` -------------------------------- ### TextHyphen.positions() Source: https://github.com/lunarisapp/text-tools/blob/main/packages/hyphen/README.md Get the hyphenation points for a given word. ```APIDOC ## TextHyphen.positions() ### Description Calculates and returns an array of indices where a word can be hyphenated. ### Method `positions(word: string): number[]` ### Parameters - **word** (string) - The word to analyze. ### Returns - `number[]` - An array of indices representing valid hyphenation points. ### Example ```typescript // Gets the textHyphenation points for a word. // Result: [2, 6] textHyphen.positions('hyphenation'); ``` ``` -------------------------------- ### Get phone-to-type mappings Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns a list of [string, string[]] mapping each ARPAbet phone symbol to its phoneme class (e.g., vowel, stop, fricative, nasal, liquid, affricate). Useful for analyzing phoneme types. ```typescript import cmudict from '@lunarisapp/cmudict'; const phonesMap = new Map(cmudict.phones()); console.log(phonesMap.get('AA')); // => ['vowel'] console.log(phonesMap.get('B')); // => ['stop'] console.log(phonesMap.get('CH')); // => ['affricate'] console.log(phonesMap.get('M')); // => ['nasal'] console.log(phonesMap.get('R')); // => ['liquid'] ``` -------------------------------- ### Get all words in the dictionary Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns a string array of every lowercase word, with one entry per pronunciation variant, in the same order as entries(). Useful for checking word existence. ```typescript import cmudict from '@lunarisapp/cmudict'; const words = cmudict.words(); console.log(words.slice(0, 5)); // => ['a', 'a', 'a', "a's", 'aaa'] (multiple entries for 'a') const isInDict = (w: string) => cmudict.dict()[w.toLowerCase()] !== undefined; console.log(isInDict('serendipity')); // => true console.log(isInDict('xyzzy')); // => false ``` -------------------------------- ### Access language dictionary constants Source: https://context7.com/lunarisapp/text-tools/llms.txt Bundled language dictionaries (e.g., `enUS`, `deDE`) are exported as named constants for direct use. This example shows how to import and use them, and iterate through supported language codes to check hyphenation positions. ```typescript import { enUS, deDE, fr, es, TextHyphen } from '@lunarisapp/hyphen'; // Use a dictionary directly (advanced) console.log(typeof enUS); // => 'string' (raw .dic content) // Supported language codes (sample) const langs = ['en', 'en_US', 'en_GB', 'de', 'de_DE', 'de_AT', 'de_CH', 'fr', 'es', 'it', 'nl', 'pl', 'pt', 'ru', 'sv', 'da'] as const; for (const lang of langs) { const h = new TextHyphen({ lang }); console.log(lang, h.positions('internationalization')); } ``` -------------------------------- ### TextHyphen.variants() Source: https://github.com/lunarisapp/text-tools/blob/main/packages/hyphen/README.md Get all possible hyphenation variants for a word. ```APIDOC ## TextHyphen.variants() ### Description Generates all possible ways to hyphenate a word based on the configured rules. ### Method `variants(word: string): string[][]` ### Parameters - **word** (string) - The word to find variants for. ### Returns - `string[][]` - An array of arrays, where each inner array represents a hyphenation variant. ### Example ```typescript // Gets the hyphenation variants for a word. // Result: [['hy', 'phenation'], ['hyphen', 'ation']] textHyphen.variants('hyphenation'); ``` ``` -------------------------------- ### Basic Text Analysis with Lunaris Language Source: https://github.com/lunarisapp/text-tools/blob/main/packages/language/README.md Import and use functions for language analysis, including getting vowels, consonants, words, sentences, and removing punctuation. Ensure the correct language type is specified for accurate results. ```typescript import { type Language, vowels, consonants, removePunctuation, getWords, getSentences } from '@lunarisapp/language'; const lang: Language = 'en_US'; const enVowels = vowels[lang]; const enConsonants = consonants[lang]; const text = 'Hello, world!'; const words = getWords(text); const sentences = getSentences(text); const textWithoutPunctuation = removePunctuation(text); ``` -------------------------------- ### Get full CMU dictionary Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns the complete CMU dictionary. Keys are lowercase words, and values are arrays of pronunciation variants, each being an array of ARPAbet phoneme tokens with stress digits. ```typescript import cmudict from '@lunarisapp/cmudict'; const d = cmudict.dict(); console.log(d['hello']); // => [['HH', 'AH0', 'L', 'OW1']] // Words with multiple pronunciations console.log(d['aalborg']); // => [['AO1', 'L', 'B', 'AO0', 'R', 'G'], ['AA1', 'L', 'B', 'AO0', 'R', 'G']] // Count syllables by filtering phonemes with digits function syllablesFromCMU(word: string): number { const prons = d[word.toLowerCase()]?.[0]; if (!prons) return 0; return prons.filter(p => /\d/.test(p)).length; } console.log(syllablesFromCMU('beautiful')); // => 3 console.log(syllablesFromCMU('hyphenation')); // => 4 ``` -------------------------------- ### Get flat list of [word, phonemes] tuples Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns every entry as a list of [string, string[]] tuples, preserving all pronunciation variants as separate tuples. Useful for iteration without the grouped-by-word structure of dict(). ```typescript import cmudict from '@lunarisapp/cmudict'; const entries = cmudict.entries(); console.log(entries.length); // => 100,000+ const [word, phonemes] = entries[0]; console.log(word, phonemes); // e.g. "a" ["AH0"] or ["EY1"] ``` -------------------------------- ### Get vowel pronunciations for symbols Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns a dictionary of non-standard words (punctuation marks, symbols) and their pronunciations, in the same Record format as dict(). Useful for handling special characters. ```typescript import cmudict from '@lunarisapp/cmudict'; const vp = cmudict.vp(); console.log(vp[',comma']); // => [['K', 'AA1', 'M', 'AH0']] console.log(vp['!exclamation-point']); // => [['EH2','K','S','K','L','AH0','M','EY1','SH','AH0','N','P','OY2','N','T']] ``` -------------------------------- ### Get all ARPAbet symbols Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns the full list of ARPAbet phoneme symbols used by the dictionary, including stress variants (e.g., AA, AA0, AA1, AA2). Useful for validating symbols or generating lists. ```typescript import cmudict from '@lunarisapp/cmudict'; const syms = cmudict.symbols(); console.log(syms.length); // => 70+ console.log(syms.includes('AH0')); // => true console.log(syms.includes('ZH')); // => true ``` -------------------------------- ### Initialize and Use TextStats Source: https://github.com/lunarisapp/text-tools/blob/main/packages/stats/README.md Import and instantiate the TextStats class to begin calculating text statistics. Options for language and caching can be configured during initialization. ```typescript import { TextStats } from '@lunarisapp/stats'; const textStats = new TextStats({ lang: 'en_US', // optional, en_US by default cache: true, // optional, true by default }); textStats.wordCount('Hello, world!'); ``` -------------------------------- ### TextStats Class Initialization Source: https://github.com/lunarisapp/text-tools/blob/main/packages/stats/README.md Initialize the TextStats class with optional language and caching configurations. ```APIDOC ## TextStats Class ### Description Initializes the TextStats class, allowing for optional language and caching configurations. ### Constructor `new TextStats(options?: { lang?: string; cache?: boolean })` ### Parameters #### Options - **lang** (string) - Optional - The language code for text analysis (e.g., 'en_US'). Defaults to 'en_US'. - **cache** (boolean) - Optional - Enables or disables caching for faster performance. Defaults to true. ### Request Example ```typescript import { TextStats } from '@lunarisapp/stats'; const textStats = new TextStats({ lang: 'en_US', cache: true, }); ``` ``` -------------------------------- ### TextHyphen Class Initialization Source: https://github.com/lunarisapp/text-tools/blob/main/packages/hyphen/README.md Initialize the TextHyphen class with optional language and hyphenation parameters. ```APIDOC ## TextHyphen Initialization ### Description Initializes a new instance of the TextHyphen class. You can specify the language and hyphenation rules. ### Parameters - **options** (object) - Optional configuration object. - **lang** (string) - The language code (e.g., 'en_US'). Defaults to 'en_US'. - **left** (number) - The minimum number of characters before the hyphen. Defaults to 2. - **right** (number) - The minimum number of characters after the hyphen. Defaults to 2. ### Example ```typescript import { TextHyphen } from '@lunarisapp/hyphen'; const textHyphen = new TextHyphen({ lang: 'en_US', left: 2, right: 2, }); ``` ``` -------------------------------- ### TextStats Constructor Source: https://context7.com/lunarisapp/text-tools/llms.txt Instantiates a statistics engine for a given language, with optional LRU caching. ```APIDOC ## new TextStats(props?) ### Description Instantiates a stats engine for the given language. For English locales, it loads the CMU dictionary for accurate syllable counts; for other languages, it falls back to hyphenation-based syllabification. LRU caching (512 entries) is enabled by default. ### Parameters #### Path Parameters - **props** (object) - Optional - Configuration properties for the stats engine. - **lang** (string) - Optional - The language code (e.g., 'en_US', 'es'). Defaults to the system's locale if not provided. - **cache** (boolean) - Optional - Whether to enable LRU caching. Defaults to `true`. ### Request Example ```typescript import { TextStats } from '@lunarisapp/stats'; const stats = new TextStats({ lang: 'en_US', cache: true }); // stats.setLang('es') to switch language at runtime ``` ``` -------------------------------- ### cmudict.vp() Source: https://context7.com/lunarisapp/text-tools/llms.txt Provides a dictionary containing pronunciations for non-standard words such as punctuation marks and symbols. The returned format is `Record`, consistent with the `dict()` method. ```APIDOC ## `cmudict.vp()` — vowel pronunciations (punctuation & symbol words) ### Description Returns a dictionary of non-standard words (punctuation marks, symbols) and their pronunciations, in the same `Record` format as `dict()`. ### Usage ```typescript import cmudict from '@lunarisapp/cmudict'; const vp = cmudict.vp(); console.log(vp[',comma']); // => [['K', 'AA1', 'M', 'AH0']] console.log(vp['!exclamation-point']); // => [['EH2','K','S','K','L','AH0','M','EY1','SH','AH0','N','P','OY2','N','T']] ``` ``` -------------------------------- ### TextReadability.lix(text) / TextReadability.rix(text) Source: https://context7.com/lunarisapp/text-tools/llms.txt Calculates the LIX and RIX ratios, which are language-agnostic readability measures. LIX is calculated as (words/sentences) + (long words × 100/words), and RIX is (long words / sentences). ```APIDOC ## TextReadability.lix(text) / TextReadability.rix(text) ### Description Language-agnostic readability ratios. LIX = (words/sentences) + (long words × 100/words). RIX = long words / sentences. Both work with any language. ### Method `lix`, `rix` ### Parameters #### Path Parameters - **text** (string) - Required - The text to analyze. ### Request Example ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en' }); const text = 'The quick brown fox jumps over the lazy dog. Simple text is easy.'; console.log(tr.lix(text)); // => ~25 (easy, < 30) console.log(tr.rix(text)); // => ~1.0 // Works for non-English too tr.setLang('sv'); console.log(tr.lix('Det snabba bruna rånet hoppar över den lata hunden.')); ``` ``` -------------------------------- ### new TextHyphen(props?) Source: https://context7.com/lunarisapp/text-tools/llms.txt Creates a hyphenator instance for a specified language, backed by LibreOffice `.dic` pattern files. You can configure the minimum number of characters to keep before (`left`) and after (`right`) a hyphenation point. Defaults to English ('en') with `left=2` and `right=2`. ```APIDOC ## `new TextHyphen(props?)` — create a hyphenator for a language ### Description Constructs a hyphenator backed by LibreOffice `.dic` pattern files. Supports 40+ languages via the `Language` type exported from `@lunarisapp/hyphen`. `left` and `right` specify the minimum number of characters to keep before/after a hyphenation point. ### Usage ```typescript import { TextHyphen } from '@lunarisapp/hyphen'; const h = new TextHyphen({ lang: 'en_US', left: 2, right: 2 }); // Default: lang='en', left=2, right=2 ``` ``` -------------------------------- ### Initialize TextReadability and Calculate Score Source: https://github.com/lunarisapp/text-tools/blob/main/packages/readability/README.md Instantiate the TextReadability class with optional language and caching configurations. Then, use its methods to calculate readability scores for a given text. ```typescript import { TextReadability } from '@lunarisapp/readability'; const textReadability = new TextReadability({ lang: 'en_US', // optional, en_US by default cache: true, // optional, true by default }); textReadability.fleschReadingEase('Hello, world!'); ``` -------------------------------- ### new TextReadability(props?) Source: https://context7.com/lunarisapp/text-tools/llms.txt Initializes a TextReadability scorer, which wraps TextStats and provides readability formulas. Supports language switching and caching. ```APIDOC ## new TextReadability(props?) — create a readability scorer ### Description Wraps `TextStats` and provides all readability formulas. Language-specific coefficients (for Flesch and related formulas) are configured automatically. Supports `setLang()` for runtime language switching. LRU caching (512 entries) is on by default. ### Constructor `new TextReadability(props?: { lang?: string; cache?: boolean })` ### Parameters #### Props - **lang** (string) - Optional - The language code for readability calculations (e.g., 'en_US', 'de'). - **cache** (boolean) - Optional - Whether to enable LRU caching. Defaults to true. ### Request Example ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en_US', cache: true }); ``` ``` -------------------------------- ### Get all hyphenation split variants Source: https://context7.com/lunarisapp/text-tools/llms.txt Use `variants` to retrieve all possible `[left, right]` string array splits for a word, ordered from rightmost to leftmost break point. The `iterate` method provides a convenient way to loop through these variants. ```typescript import { TextHyphen } from '@lunarisapp/hyphen'; const h = new TextHyphen({ lang: 'en_US' }); console.log(h.variants('hyphenation')); // => [['hyphen', 'ation'], ['hy', 'phenation']] // Iterate manually for (const [l, r] of h.iterate('hyphenation')) { console.log(`${l} | ${r}`); } // hyphen | ation // hy | phenation ``` -------------------------------- ### Importing Language Utilities Source: https://github.com/lunarisapp/text-tools/blob/main/packages/stats/README.md Import specific linguistic utility functions like 'consonants' and 'vowels' from the library. This allows for more granular text analysis. ```typescript import { consonants, vowels, type Language } from '@lunarisapp/stats'; ``` -------------------------------- ### Helper Imports Source: https://github.com/lunarisapp/text-tools/blob/main/packages/stats/README.md Importing helper functions and types for advanced usage. ```APIDOC ## Helper Imports ### Description Import specific helper functions or types for more granular control or integration with other libraries. ### Imports ```typescript import { consonants, vowels, type Language } from '@lunarisapp/stats'; ``` ### Usage Example ```typescript import { consonants, vowels, type Language } from '@lunarisapp/stats'; // Example usage of imported functions/types would go here if documented. // For instance, if 'consonants' and 'vowels' were standalone functions: // const consonantList = consonants('example'); // const vowelList = vowels('example'); // const lang: Language = 'en_US'; ``` ``` -------------------------------- ### Create a TextStats engine Source: https://context7.com/lunarisapp/text-tools/llms.txt Instantiate a `TextStats` engine for a given language. English locales use the CMU dictionary for syllable counts, while others fall back to hyphenation. LRU caching is enabled by default. ```typescript import { TextStats } from '@lunarisapp/stats'; const stats = new TextStats({ lang: 'en_US', cache: true }); // stats.setLang('es') to switch language at runtime ``` -------------------------------- ### TextReadability.gulpeaseIndex(text) Source: https://context7.com/lunarisapp/text-tools/llms.txt Calculates the Gulpease Index for Italian text. Scores range from 0 to 100, with higher scores indicating easier readability. ```APIDOC ## TextReadability.gulpeaseIndex(text) ### Description Calculates the Gulpease Index for Italian text. Scores range from 0 to 100, with higher scores indicating easier readability. Scores above 80 are easy for elementary readers; below 40 are very difficult. ### Method `TextReadability.gulpeaseIndex` ### Parameters #### Path Parameters - **text** (string) - Required - The text to analyze. ### Request Example ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'it' }); const text = 'Il gatto è seduto sul tappeto. Il sole splende nel cielo.'; console.log(tr.gulpeaseIndex(text)); // => ~60-70 for simple Italian ``` ### Response #### Success Response (number) - Returns a number representing the Gulpease Index score. ``` -------------------------------- ### Calculate LIX and RIX Ratios Source: https://context7.com/lunarisapp/text-tools/llms.txt Language-agnostic readability ratios. LIX uses sentence and word length, while RIX focuses on the proportion of long words per sentence. Both work with any language. ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en' }); const text = 'The quick brown fox jumps over the lazy dog. Simple text is easy.'; console.log(tr.lix(text)); // => ~25 (easy, < 30) console.log(tr.rix(text)); // => ~1.0 // Works for non-English too tr.setLang('sv'); console.log(tr.lix('Det snabba bruna rånet hoppar över den lata hunden.')); ``` -------------------------------- ### TextReadability.linsearWriteFormula(text, sample?) Source: https://context7.com/lunarisapp/text-tools/llms.txt Applies the Linsear Write formula, which classifies words as 'easy' (≤2 syllables) or 'hard' (3+ syllables). The analysis can be limited to the first `sample` words, defaulting to 100. ```APIDOC ## TextReadability.linsearWriteFormula(text, sample?) ### Description Readability formula that classifies words as "easy" (≤2 syllables) or "hard" (3+ syllables). Operates on the first `sample` words (default 100). ### Method `linsearWriteFormula` ### Parameters #### Path Parameters - **text** (string) - Required - The text to analyze. - **sample** (number) - Optional - The number of words to consider for the analysis. Defaults to 100. ### Request Example ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en' }); const text = 'The quick brown fox jumps. The lazy dog slept.'; console.log(tr.linsearWriteFormula(text)); // default 100-word sample console.log(tr.linsearWriteFormula(text, 20)); // custom sample size ``` ``` -------------------------------- ### Calculate Gulpease Index (Italian) Source: https://context7.com/lunarisapp/text-tools/llms.txt Use the `gulpeaseIndex` method to calculate the Italian readability score for a given text. Ensure the `TextReadability` instance is configured for Italian (`lang: 'it'`). ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'it' }); const text = 'Il gatto è seduto sul tappeto. Il sole splende nel cielo.'; console.log(tr.gulpeaseIndex(text)); // => ~60-70 for simple Italian ``` -------------------------------- ### cmudict.entries() Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns all entries from the CMU dictionary as a flat list of `[word, phonemes]` tuples. This format preserves all pronunciation variants as separate tuples, making it suitable for iteration without the grouped-by-word structure of `dict()`. ```APIDOC ## `cmudict.entries()` — flat list of `[word, phonemes]` tuples ### Description Returns every entry as `[string, string[]][]`, preserving all pronunciation variants as separate tuples. Useful for iteration without the grouped-by-word structure of `dict()`. ### Usage ```typescript import cmudict from '@lunarisapp/cmudict'; const entries = cmudict.entries(); console.log(entries.length); // => 100,000+ const [word, phonemes] = entries[0]; console.log(word, phonemes); // e.g. "a" ["AH0"] or ["EY1"] ``` ``` -------------------------------- ### cmudict.words() Source: https://context7.com/lunarisapp/text-tools/llms.txt Provides a string array containing all lowercase words from the dictionary. Each pronunciation variant of a word appears as a separate entry, maintaining the same order as `entries()`. ```APIDOC ## `cmudict.words()` — all words in the dictionary ### Description Returns a `string[]` of every lowercase word (one entry per pronunciation variant, same order as `entries()`). ### Usage ```typescript import cmudict from '@lunarisapp/cmudict'; const words = cmudict.words(); console.log(words.slice(0, 5)); // => ['a', 'a', 'a', "a's", 'aaa'] (multiple entries for 'a') const isInDict = (w: string) => cmudict.dict()[w.toLowerCase()] !== undefined; console.log(isInDict('serendipity')); // => true console.log(isInDict('xyzzy')); // => false ``` ``` -------------------------------- ### Use Pure Readability Formulas Directly Source: https://github.com/lunarisapp/text-tools/blob/main/packages/readability/README.md Import and use individual readability formulas directly by providing the required text statistics. This is useful when you have pre-calculated counts. ```typescript import { fleschReadingEase } from '@lunarisapp/readability'; fleschReadingEase({ wordCount: 2, sentenceCount: 1, syllableCount: 6, }); ``` -------------------------------- ### Initialize TextReadability Scorer Source: https://context7.com/lunarisapp/text-tools/llms.txt Creates an instance of TextReadability, which wraps TextStats and provides readability formulas. Supports language configuration and caching. ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en_US', cache: true }); ``` -------------------------------- ### Direct Formula Invocation with Pre-computed Stats Source: https://context7.com/lunarisapp/text-tools/llms.txt Use pure formula functions for custom pipelines by providing pre-computed statistics. This bypasses class instantiation and is ideal for serverless or edge environments. ```typescript import { fleschReadingEase, fleschKincaidGrade, smogIndex, gunningFog, colemanLiauIndex, automatedReadabilityIndex, linsearWriteFormula, gulpeaseIndex, gutierrezPolini, wienerSachtextformel, mcalpineEflaw, lix, rix, } from '@lunarisapp/readability'; // Provide your own pre-computed stats console.log(fleschReadingEase({ sentences: 15.0, syllablesPerWord: 1.5, coefficients: { base: 206.835, sentences: 1.015, syllablesPerWord: 84.6 }, })); // => ~57 console.log(fleschKincaidGrade({ sentences: 15.0, syllablesPerWord: 1.5 })); console.log(smogIndex({ sentences: 30, polysyllables: 20 })); console.log(automatedReadabilityIndex({ chars: 500, words: 100, sentences: 5 })); console.log(mcalpineEflaw({ words: 100, sentences: 4, miniWords: 30 })); console.log(lix({ words: 100, longWords: 20, wordsPerSentence: 15 })); console.log(rix({ longWords: 20, sentences: 5 })); ``` -------------------------------- ### Perform basic text counts Source: https://context7.com/lunarisapp/text-tools/llms.txt Utilize core counting methods like `wordCount`, `charCount`, `letterCount`, `vowelCount`, and `consonantCount`. `charCount` includes all non-space characters, `letterCount` excludes punctuation, and vowel/consonant counts use per-language maps. The language can be switched at runtime using `setLang`. ```typescript import { TextStats } from '@lunarisapp/stats'; const stats = new TextStats({ lang: 'en_US' }); const text = 'The quick brown fox jumps over the lazy dog.'; console.log(stats.wordCount(text)); // => 9 console.log(stats.charCount(text)); // => 35 (no spaces) console.log(stats.letterCount(text)); // => 35 console.log(stats.vowelCount(text)); // => 11 console.log(stats.consonantCount(text)); // => 24 // Spanish stats.setLang('es'); const es = 'El rápido zorro marrón salta sobre el perro perezoso.'; console.log(stats.vowelCount(es)); // includes accented vowels á ``` -------------------------------- ### Split text into sentences with @lunarisapp/language Source: https://context7.com/lunarisapp/text-tools/llms.txt Use the `getSentences` function to split text into an array of trimmed sentence strings. It handles various sentence-ending punctuation and newlines. ```typescript import { getSentences } from '@lunarisapp/language'; const sentences = getSentences('The cat sat. The dog ran! Why?'); // => ['The cat sat.', 'The dog ran!', 'Why?'] const multi = getSentences('First line\nSecond line.'); // => ['First line', 'Second line.'] ``` -------------------------------- ### cmudict.phones() Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns an array of `[string, string[]]` tuples that map each ARPAbet phone symbol to its corresponding phoneme class, such as `vowel`, `stop`, `fricative`, `nasal`, `liquid`, or `affricate`. ```APIDOC ## `cmudict.phones()` — phone-to-type mappings ### Description Returns `[string, string[]][]` mapping each ARPAbet phone symbol to its phoneme class (e.g., `vowel`, `stop`, `fricative`, `nasal`, `liquid`, `affricate`). ### Usage ```typescript import cmudict from '@lunarisapp/cmudict'; const phonesMap = new Map(cmudict.phones()); console.log(phonesMap.get('AA')); // => ['vowel'] console.log(phonesMap.get('B')); // => ['stop'] console.log(phonesMap.get('CH')); // => ['affricate'] console.log(phonesMap.get('M')); // => ['nasal'] console.log(phonesMap.get('R')); // => ['liquid'] ``` ``` -------------------------------- ### Tokenize text into words with @lunarisapp/language Source: https://context7.com/lunarisapp/text-tools/llms.txt Use the `getWords` function to split text into an array of lowercase word tokens. Punctuation is removed by default, but can be preserved by passing `false` as the second argument. ```typescript import { getWords } from '@lunarisapp/language'; const words = getWords('Hello, world! It\'s a test.'); // => ['hello', 'world', "it's", 'a', 'test'] const withPunct = getWords('Hello, world!', false); // => ['hello,', 'world!'] ``` -------------------------------- ### Create a hyphenator for a language Source: https://context7.com/lunarisapp/text-tools/llms.txt Constructs a hyphenator backed by LibreOffice .dic pattern files. Supports 40+ languages. left and right specify the minimum number of characters to keep before/after a hyphenation point. ```typescript import { TextHyphen } from '@lunarisapp/hyphen'; const h = new TextHyphen({ lang: 'en_US', left: 2, right: 2 }); // Default: lang='en', left=2, right=2 ``` -------------------------------- ### getSentences(text) Source: https://context7.com/lunarisapp/text-tools/llms.txt Splits text into an array of trimmed sentence strings. It handles various sentence-ending punctuation marks and multi-line text. ```APIDOC ## getSentences(text) ### Description Splits input text into an array of sentences. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```typescript import { getSentences } from '@lunarisapp/language'; const sentences = getSentences('The cat sat. The dog ran! Why?'); // => ['The cat sat.', 'The dog ran!', 'Why?'] const multi = getSentences('First line\nSecond line.'); // => ['First line', 'Second line.'] ``` ### Response #### Success Response (200) - **sentences** (string[]) - An array of sentence strings. ``` -------------------------------- ### Pure Formula Functions Source: https://context7.com/lunarisapp/text-tools/llms.txt Directly invoke readability formulas with pre-computed statistics for custom processing pipelines. ```APIDOC ## Pure Formula Functions ### Description These are standalone pure functions that accept pre-computed statistics, allowing for direct invocation of readability formulas without instantiating the `TextReadability` class. This is useful for custom pipelines or environments where class instantiation is not desired. ### Available Functions - `fleschReadingEase({ sentences, syllablesPerWord, coefficients })` - `fleschKincaidGrade({ sentences, syllablesPerWord })` - `smogIndex({ sentences, polysyllables })` - `gunningFog({ sentences, words, syllablesPerWord })` - `colemanLiauIndex({ characters, words, sentences })` - `automatedReadabilityIndex({ characters, words, sentences })` - `linsearWriteFormula({ words, sentences, syllablesPerWord })` - `gulpeaseIndex({ sentences, words, syllablesPerWord })` - `gutierrezPolini({ sentences, words, syllablesPerWord })` - `wienerSachtextformel({ sentences, words, polysyllables, variant })` - `mcalpineEflaw({ words, sentences, miniWords })` - `lix({ words, longWords, wordsPerSentence })` - `rix({ longWords, sentences })` ### Parameters Parameters vary per function. Refer to the specific function signature for details. Common parameters include: - **sentences** (number): Total number of sentences. - **words** (number): Total number of words. - **syllablesPerWord** (number): Average syllables per word. - **characters** (number): Total number of characters. - **polysyllables** (number): Total number of polysyllabic words. - **longWords** (number): Total number of long words. - **wordsPerSentence** (number): Average words per sentence. - **miniWords** (number): Total number of mini-words. - **coefficients** (object): Coefficients for specific formulas (e.g., `base`, `sentences`, `syllablesPerWord`). - **variant** (number): Formula variant for `wienerSachtextformel`. ### Request Example ```typescript import { fleschReadingEase, fleschKincaidGrade, smogIndex, gunningFog, colemanLiauIndex, automatedReadabilityIndex, linsearWriteFormula, gulpeaseIndex, gutierrezPolini, wienerSachtextformel, mcalpineEflaw, lix, rix, } from '@lunarisapp/readability'; // Provide your own pre-computed stats console.log(fleschReadingEase({ sentences: 15.0, syllablesPerWord: 1.5, coefficients: { base: 206.835, sentences: 1.015, syllablesPerWord: 84.6 }, })); // => ~57 console.log(fleschKincaidGrade({ sentences: 15.0, syllablesPerWord: 1.5 })); console.log(smogIndex({ sentences: 30, polysyllables: 20 })); console.log(automatedReadabilityIndex({ chars: 500, words: 100, sentences: 5 })); console.log(mcalpineEflaw({ words: 100, sentences: 4, miniWords: 30 })); console.log(lix({ words: 100, longWords: 20, wordsPerSentence: 15 })); console.log(rix({ longWords: 20, sentences: 5 })); ``` ### Response #### Success Response (number) - Returns a number representing the calculated readability score. ``` -------------------------------- ### TextReadability.wienerSachtextformel(text, variant?) Source: https://context7.com/lunarisapp/text-tools/llms.txt Calculates the Wiener Sachtextformel for German text. Supports four variants, each weighting different linguistic statistics differently. ```APIDOC ## TextReadability.wienerSachtextformel(text, variant?) ### Description Calculates the Wiener Sachtextformel for German text. Supports four variants (1-4), each weighting polysyllables, monosyllables, long words, and sentence statistics differently. All variants use these statistics but weight them differently. ### Method `TextReadability.wienerSachtextformel` ### Parameters #### Path Parameters - **text** (string) - Required - The text to analyze. - **variant** (number) - Optional - The variant of the formula to use (1-4). Defaults to 1 if not provided. ### Request Example ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'de' }); const simple = 'Alle meine Entchen schwimmen auf dem See. Köpfchen unters Wasser.'; const complex = 'Die Bundesregierung beschloss weitreichende wirtschaftspolitische Maßnahmen.'; console.log(tr.wienerSachtextformel(simple, 1)); // ~3-4 (simple) console.log(tr.wienerSachtextformel(complex, 1)); // ~13-14 (complex) console.log(tr.wienerSachtextformel(complex, 2)); // variant 2 console.log(tr.wienerSachtextformel(complex, 3)); // variant 3 console.log(tr.wienerSachtextformel(complex, 4)); // variant 4 ``` ### Response #### Success Response (number) - Returns a number representing the Wiener Sachtextformel score. ``` -------------------------------- ### TextHyphen.wrap() Source: https://github.com/lunarisapp/text-tools/blob/main/packages/hyphen/README.md Wrap a word with hyphens at specified positions. ```APIDOC ## TextHyphen.wrap() ### Description Inserts hyphens into a word at the first valid hyphenation point found after a specified index. ### Method `wrap(word: string, index: number): string` ### Parameters - **word** (string) - The word to wrap. - **index** (number) - The index after which to insert the hyphen. ### Returns - `string` - The word with a hyphen inserted. ### Example ```typescript // Wraps a word with hyphens at the given positions. // Result: 'hy-phenation' textHyphen.wrap('hy-phenation', 3); ``` ``` -------------------------------- ### TextReadability.smogIndex(text) Source: https://context7.com/lunarisapp/text-tools/llms.txt Estimates the years of education needed to understand the text using the SMOG Index. Requires at least three sentences; otherwise, it returns 0. ```APIDOC ## TextReadability.smogIndex(text) ### Description Estimates years of education needed. Requires ≥3 sentences; returns 0 otherwise. ### Method `smogIndex` ### Parameters #### Path Parameters - **text** (string) - Required - The text to analyze. ### Request Example ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en' }); const text = [ 'The patient exhibited symptoms of myocardial infarction.', 'Electrocardiographic evaluation confirmed the diagnosis.', 'Pharmacological intervention was immediately initiated.', ].join(' '); console.log(tr.smogIndex(text)); // => ~14+ ``` ``` -------------------------------- ### TextReadability.fleschReadingEase(text) Source: https://context7.com/lunarisapp/text-tools/llms.txt Calculates the Flesch Reading Ease score for a given text, ranging from 0 (difficult) to 100+ (easy). Supports multiple languages and throws an error for unsupported languages like Polish. ```APIDOC ## TextReadability.fleschReadingEase(text) — Flesch Reading Ease score ### Description Score from 0 (very difficult) to 100+ (very easy). Language-specific coefficients are applied automatically for `en`, `de`, `es`, `fr`, `it`, `nl`, `ru`, `hu`. Polish (`pl`) is not supported and throws. ### Method `fleschReadingEase(text: string): number` ### Parameters #### Path Parameters - **text** (string) - Required - The input text to analyze. ### Request Example ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en' }); const text = 'The cat sat on the mat. It was a fine day.'; console.log(tr.fleschReadingEase(text)); // => ~80+ (easy) tr.setLang('de'); console.log(tr.fleschReadingEase(text)); // German coefficients tr.setLang('es'); console.log(tr.fleschReadingEase('El sol brilla en el cielo azul.')); // ~90+ // Polish throws tr.setLang('pl'); try { tr.fleschReadingEase(text); } catch (e) { console.error(e.message); } ``` ### Response #### Success Response (number) - Returns the Flesch Reading Ease score. ``` -------------------------------- ### cmudict.dict() Source: https://context7.com/lunarisapp/text-tools/llms.txt Retrieves the complete CMU Pronouncing Dictionary. The keys are lowercase words, and the values are arrays of pronunciation variants, where each variant is an array of ARPAbet phoneme tokens. Stress digits (0/1/2) are appended to vowel phonemes. ```APIDOC ## `cmudict.dict()` — full CMU Pronouncing Dictionary ### Description Returns the complete CMU dictionary as `Record`. Keys are lowercase words; values are arrays of pronunciation variants, each variant being an array of ARPAbet phoneme tokens. Stress digits (0/1/2) are attached to vowel phonemes. ### Usage ```typescript import cmudict from '@lunarisapp/cmudict'; const d = cmudict.dict(); console.log(d['hello']); // => [['HH', 'AH0', 'L', 'OW1']] // Words with multiple pronunciations console.log(d['aalborg']); // => [['AO1', 'L', 'B', 'AO0', 'R', 'G'], ['AA1', 'L', 'B', 'AO0', 'R', 'G']] // Count syllables by filtering phonemes with digits function syllablesFromCMU(word: string): number { const prons = d[word.toLowerCase()]?.[0]; if (!prons) return 0; return prons.filter(p => /\d/.test(p)).length; } console.log(syllablesFromCMU('beautiful')); // => 3 console.log(syllablesFromCMU('hyphenation')); // => 4 ``` ``` -------------------------------- ### Calculate SMOG Index Source: https://context7.com/lunarisapp/text-tools/llms.txt Estimates the years of education needed to understand the text. Requires at least 3 sentences; returns 0 otherwise. ```typescript import { TextReadability } from '@lunarisapp/readability'; const tr = new TextReadability({ lang: 'en' }); const text = [ 'The patient exhibited symptoms of myocardial infarction.', 'Electrocardiographic evaluation confirmed the diagnosis.', 'Pharmacological intervention was immediately initiated.', ].join(' '); console.log(tr.smogIndex(text)); // => ~14+ ``` -------------------------------- ### cmudict.symbols() Source: https://context7.com/lunarisapp/text-tools/llms.txt Returns a comprehensive list of all ARPAbet phoneme symbols utilized by the dictionary, including their stress variants (e.g., `AA`, `AA0`, `AA1`, `AA2`). ```APIDOC ## `cmudict.symbols()` — all ARPAbet symbols ### Description Returns the full list of ARPAbet phoneme symbols used by the dictionary, including stress variants (e.g., `AA`, `AA0`, `AA1`, `AA2`). ### Usage ```typescript import cmudict from '@lunarisapp/cmudict'; const syms = cmudict.symbols(); console.log(syms.length); // => 70+ console.log(syms.includes('AH0')); // => true console.log(syms.includes('ZH')); // => true ``` ``` -------------------------------- ### consonants Source: https://context7.com/lunarisapp/text-tools/llms.txt A static record mapping language codes to arrays of consonant characters, including language-specific ones. ```APIDOC ## consonants ### Description Provides per-language consonant character maps. ### Parameters - None ### Usage ```typescript import { consonants } from '@lunarisapp/language'; console.log(consonants['es']); // => [...latin consonants, 'ñ'] console.log(consonants['de_DE']); // => [...latin consonants, 'ß'] console.log(consonants['fr']); // => [...latin consonants, 'ç'] ``` ### Response #### Success Response (200) - **consonants** (Record) - A record where keys are language codes and values are arrays of consonant characters. ```