UNPKG

just-exercise-parser

Version:

A TypeScript library for parsing, normalizing, and generating standardized exercise names

189 lines (188 loc) 6.49 kB
/** * Enhanced system for parsing, normalizing, and generating standardized exercise names */ export declare class ExerciseNameFormatter { private static readonly DEBUG_ENV_VAR; private static isDebugging; /** * Dictionary of exercise component categories and their terms */ private exerciseComponentDefinitions; /** * Dictionary of templates for standardized exercise naming */ private templates; /** * List of regex replacements for text normalization */ private regexReplacements; /** * Dictionary of exercise component categories and their terms with regex patterns */ private exerciseComponentPatterns; /** * Constructor that initializes the processor with JSON configuration * @param config Optional configuration object to use instead of the default */ constructor(config?: ExerciseConfigJson); /** * Checks if debugging is enabled via environment variable. * This method is static so the `isDebugging` flag can be static. * @returns True if debugging is enabled, false otherwise. */ private static isDebugEnabled; /** * Logs debug messages if debugging is enabled. * @param message The message to log. * @param optionalParams Optional parameters to log. */ private static debugLog; /** * Logs error messages. Always logs errors regardless of debug mode. * @param message The error message. * @param optionalParams Optional parameters */ private static errorLog; /** * Load configuration from a JSON object * @param config The configuration object */ loadConfig(config: ExerciseConfigJson): void; /** * Initialize regex patterns from component definitions */ private initializePatterns; /** * Standardize an exercise name by applying regex replacements and normalization * @param exerciseName The exercise name to standardize * @returns Standardized exercise name */ standardizeName(exerciseName: string): string; /** * Clean an exercise name using regex replacements * @param exerciseName Exercise name to clean * @returns Cleaned exercise name */ cleanExerciseName(exerciseName: string): string; /** * Normalize an exercise name for comparison * @param exerciseName Exercise name to normalize * @param internalName Whether this is an internal name * @returns Normalized exercise name */ normalizeName(exerciseName: string, internalName?: boolean): string; /** * Check if an exercise is alternating * @param exerciseName Exercise name to check * @returns Object with isAlternating flag and cleanedName */ private isAlternatingExercise; /** * Helper method to move specific words to beginning or end * @param text Text to process * @returns Text with words moved to specific positions */ private moveWordsToSpecificPositions; /** * Remove pluralization from words in an exercise name * @param exerciseName Exercise name to process * @returns Exercise name with pluralization removed */ private static cleanPluralizationUnsafe; /** * Remove pluralization from a single word * @param word Word to process * @returns Word with pluralization removed */ private static removePluralization; /** * Check if a character is a vowel * @param c Character to check * @returns True if the character is a vowel */ private static isVowel; /** * Sort words in an exercise name alphabetically * @param exerciseName Exercise name to sort * @returns Exercise name with words sorted alphabetically */ private static sortWords; /** * Convert text to title case * @param input Text to convert * @param customExceptions Custom exceptions to title case rules * @returns Text in title case */ static toTitleCase(input: string, customExceptions?: string[]): string; /** * Capitalize the first letter of a word * @param word Word to capitalize * @returns Word with first letter capitalized */ private static capitalizeFirstLetter; /** * Parses an exercise name into its component parts using regex pattern matching * @param exerciseName The full exercise name to parse * @returns Component parts of the exercise */ parseExerciseName(exerciseName: string): ExerciseComponents; /** * Checks if a position falls within any excluded segment * @param start Start position * @param end End position * @param excludedSegments List of excluded segments * @returns True if the position is within an excluded segment */ private static isInExcludedSegment; /** * Merges overlapping segments * @param segments List of segments to merge * @returns List of merged segments */ private static mergeSegments; /** * Generate a new exercise name from components using a template * @param components The component parts to use * @param templateName Template name to use (defaults to "standard") * @returns Generated exercise name */ generateExerciseName(components: Record<string, string[]>, templateName?: string): string; /** * Process a single exercise name with normalization and standardization * @param exerciseName Exercise name to process * @param templateNames List of template names to generate variations * @returns Processed exercise */ processExerciseName(exerciseName: string, templateNames?: string[]): ProcessedExercise; } /** * Represents the parsed components of an exercise name */ export interface ExerciseComponents { originalName: string; components: Record<string, string[]>; } /** * Represents a processed exercise with original name, parsed components, and potential variations */ export interface ProcessedExercise { original: string; parsed: Record<string, string[]>; variations: string[]; } /** * Configuration structure for regex replacements */ export interface RegexReplacementConfig { pattern: string; replacement: string; ignoreCase?: boolean; } /** * Configuration JSON structure */ export interface ExerciseConfigJson { templates: Record<string, string>; components: Record<string, string[]>; replacements?: RegexReplacementConfig[]; }