@regele/devtools
Version:
A collection of developer utilities for code processing and text analysis
247 lines (246 loc) • 6.65 kB
TypeScript
import { WordCountStats, WritingSpeedStats, WritingSession, HandwritingTimerOptions } from './utils';
import { FileOptions, FileResult } from './cli/fileUtils';
/**
* Analysis result for a file
*/
export interface AnalysisResult extends FileResult {
stats?: WordCountStats;
frequentWords?: [string, number][];
readabilityScore?: number;
}
/**
* Word Counter class for analyzing text
*/
export declare class WordCounter {
private text;
private stats;
private wordsPerMinute;
private handwritingWpm;
private keyboardWpm;
private handwritingTimer;
/**
* Create a new WordCounter instance
*
* @param text - Initial text to analyze
* @param wordsPerMinute - Reading speed in words per minute
* @param handwritingWpm - Handwriting speed in words per minute
* @param keyboardWpm - Keyboard typing speed in words per minute
* @param timerOptions - Options for the handwriting timer
*/
constructor(text?: string, wordsPerMinute?: number, handwritingWpm?: number, keyboardWpm?: number, timerOptions?: HandwritingTimerOptions);
/**
* Set text to analyze
*
* @param text - The text to analyze
*/
setText(text: string): void;
/**
* Get the current text
*
* @returns The current text
*/
getText(): string;
/**
* Set reading speed
*
* @param wordsPerMinute - Reading speed in words per minute
*/
setReadingSpeed(wordsPerMinute: number): void;
/**
* Get reading speed
*
* @returns Reading speed in words per minute
*/
getReadingSpeed(): number;
/**
* Get all text statistics
*
* @returns Word count statistics
*/
getStats(): WordCountStats;
/**
* Get character count
*
* @returns Total number of characters
*/
getCharacterCount(): number;
/**
* Get character count excluding spaces
*
* @returns Number of characters excluding spaces
*/
getCharacterCountNoSpaces(): number;
/**
* Get word count
*
* @returns Number of words
*/
getWordCount(): number;
/**
* Get sentence count
*
* @returns Number of sentences
*/
getSentenceCount(): number;
/**
* Get paragraph count
*
* @returns Number of paragraphs
*/
getParagraphCount(): number;
/**
* Get estimated reading time
*
* @returns Reading time as a formatted string
*/
getReadingTime(): string;
/**
* Get estimated handwriting time
*
* @returns Handwriting time as a formatted string
*/
getHandwritingTime(): string;
/**
* Get estimated keyboard typing time
*
* @returns Keyboard typing time as a formatted string
*/
getKeyboardTime(): string;
/**
* Set handwriting speed
*
* @param wordsPerMinute - Handwriting speed in words per minute
*/
setHandwritingSpeed(wordsPerMinute: number): void;
/**
* Get handwriting speed
*
* @returns Handwriting speed in words per minute
*/
getHandwritingSpeed(): number;
/**
* Set keyboard typing speed
*
* @param wordsPerMinute - Keyboard typing speed in words per minute
*/
setKeyboardSpeed(wordsPerMinute: number): void;
/**
* Get keyboard typing speed
*
* @returns Keyboard typing speed in words per minute
*/
getKeyboardSpeed(): number;
/**
* Calculate all text statistics
*
* @returns Word count statistics
*/
private calculateStats;
/**
* Format time value in minutes to a human-readable string
*
* @param minutes - Time in minutes
* @returns Formatted time string
*/
private formatTimeValue;
/**
* Estimate handwriting time using a more realistic algorithm
*
* @param words - Number of words
* @param characters - Number of characters
* @returns Formatted time estimate
*/
private estimateHandwritingTime;
/**
* Get the frequency of each word in the text
*
* @returns Object with words as keys and their frequencies as values
*/
getWordFrequency(): Record<string, number>;
/**
* Get the most frequent words in the text
*
* @param limit - Maximum number of words to return
* @returns Array of [word, frequency] pairs sorted by frequency
*/
getMostFrequentWords(limit?: number): [string, number][];
/**
* Calculate the readability score (Flesch Reading Ease)
* Higher scores indicate easier readability (90-100: Very easy, 0-30: Very difficult)
*
* @returns Readability score between 0 and 100
*/
getReadabilityScore(): number;
/**
* Count the approximate number of syllables in the text
*
* @returns Estimated syllable count
*/
private countSyllables;
/**
* Start a writing session timer
*/
startWritingSession(): void;
/**
* Pause the writing session timer
*/
pauseWritingSession(): void;
/**
* Stop the writing session timer
*/
stopWritingSession(): void;
/**
* Reset the writing session timer
*/
resetWritingSession(): void;
/**
* Update text and take a snapshot for the timer
*
* @param text - The new text
*/
updateText(text: string): void;
/**
* Get the current writing speed
*
* @returns Writing speed statistics
*/
getWritingSpeed(): WritingSpeedStats;
/**
* Get the writing session history
*
* @returns Array of writing sessions
*/
getWritingSessionHistory(): WritingSession[];
/**
* Get the elapsed time of the current writing session
*
* @returns Elapsed time in milliseconds
*/
getElapsedTime(): number;
/**
* Get formatted elapsed time of the current writing session
*
* @returns Formatted time string (HH:MM:SS)
*/
getFormattedElapsedTime(): string;
/**
* Check if the writing timer is running
*
* @returns True if timer is running
*/
isTimerRunning(): boolean;
/**
* Set a callback function for timer tick events
*
* @param callback - Function to call on each tick
*/
onTimerTick(callback: (elapsedTime: number) => void): void;
/**
* Analyze multiple files
*
* @param patterns - Glob patterns to match files
* @param options - File options
* @returns Results of the analysis
*/
analyzeFiles(patterns: string | string[], options?: FileOptions): Promise<AnalysisResult[]>;
}