"""Helper functions for data cleaning and validation.""" import re from typing import Optional def clean_text(text: Optional[str]) -> str: """Clean text by removing extra whitespace.""" if not text: return "" return " ".join(text.split()) def parse_rating(rating: Optional[str]) -> Optional[float]: """Parse rating string to float.""" if not rating: return None match = re.search(r'[0-9.]+', str(rating)) return float(match.group()) if match else None def parse_installs(installs: Optional[str]) -> Optional[int]: """Parse installs string to integer.""" if not installs: return None match = re.search(r'[0-9,]+', str(installs)) if match: return int(match.group().replace(',', '')) return None def validate_app_id(app_id: str) -> bool: """Validate app ID format.""" return bool(re.match(r'^[a-zA-Z0-9._]+$', app_id))