UNPKG

cmu-syllable-counter

Version:

Fast and accurate syllable counter for English words using CMU Dictionary

93 lines 2.64 kB
export interface SyllableInfo { /** The original word */ word: string; /** Number of syllables */ syllables: number; /** Hyphenated version of the word */ hyphenated: string; /** Source of the syllable count: 'cmu' or 'fallback' */ source: "cmu" | "fallback"; /** CMU pronunciation if available */ pronunciation?: string; /** Syllable boundaries for advanced analysis */ syllableBoundaries?: number[]; } export interface SyllableCountOptions { /** Whether to include syllable boundaries in the result */ includeBoundaries?: boolean; } export interface HyphenationOptions { /** Whether to include syllable boundaries */ includeBoundaries?: boolean; /** Custom hyphenation patterns */ customPatterns?: Record<string, string>; /** Delimiter to use for hyphenation (default: '-') */ delimiter?: string; } /** * Main syllable counter that provides comprehensive syllable analysis * Uses CMU Dictionary with intelligent fallback algorithms */ export declare class SyllableCounter { private cache; private maxCacheSize; constructor(maxCacheSize?: number); /** * Get detailed syllable information for a word */ getSyllableInfo(word: string, options?: SyllableCountOptions & HyphenationOptions): Promise<SyllableInfo>; /** * Create a cache key that excludes delimiter (since it doesn't affect core data) */ private createCacheKey; /** * Apply delimiter transformation to a result */ private applyDelimiterToResult; /** * Process a word through CMU dictionary or fallback */ private processWord; /** * Process word using fallback algorithm */ private processWithFallback; /** * Create empty syllable info for invalid input */ private createEmptySyllableInfo; /** * Get syllable boundaries from a hyphenated string */ private getSyllableBoundariesFromHyphenated; /** * Get result from cache with LRU update */ private getFromCache; /** * Cache a result with true LRU eviction */ private cacheResult; /** * Evict oldest cache entries (true LRU) */ private evictOldestEntries; /** * Clear the cache */ clearCache(): void; /** * Get cache statistics */ getCacheStats(): { size: number; maxSize: number; oldestEntry?: number; }; /** * Set cache size limit */ setCacheSize(size: number): void; } export declare const syllableCounter: SyllableCounter; //# sourceMappingURL=syllable-counter.d.ts.map