Spaces:
Running
Running
| export const normalizePhoneNumber = (phone: string): string => { | |
| let normalized = phone | |
| .replace(/O/g, "0") | |
| .replace(/o/g, "0") | |
| .replace(/I/g, "1") | |
| .replace(/l/g, "1") | |
| .replace(/[^\d+]/g, "") | |
| .trim(); | |
| return normalized; | |
| }; | |
| export const normalizeName = (name: string): string => { | |
| if (!name) return name; | |
| return name | |
| .trim() | |
| .replace(/\s+/g, " ") | |
| .split(" ") | |
| .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) | |
| .join(" "); | |
| }; | |
| export const normalizeDate = (dateStr: string): string | null => { | |
| if (!dateStr) return null; | |
| try { | |
| const cleaned = dateStr.trim(); | |
| let date: Date; | |
| if (cleaned.includes("/")) { | |
| const parts = cleaned.split("/").map(Number); | |
| if (parts.length === 3) { | |
| let [d, m, y] = parts; | |
| if (y < 100) y += 2000; | |
| date = new Date(y, m - 1, d); | |
| } else { | |
| return null; | |
| } | |
| } else if (cleaned.includes("-")) { | |
| const parts = cleaned.split("-").map(Number); | |
| if (parts.length === 3) { | |
| let [y, m, d] = parts; | |
| if (y < 100) y += 2000; | |
| date = new Date(y, m - 1, d); | |
| } else { | |
| return null; | |
| } | |
| } else { | |
| date = new Date(cleaned); | |
| } | |
| if (isNaN(date.getTime())) return null; | |
| return date.toISOString().split("T")[0]; | |
| } catch { | |
| return null; | |
| } | |
| }; | |
| export const normalizeNumeric = (value: string): string => { | |
| return value.replace(/O/g, "0").replace(/o/g, "0").replace(/I/g, "1").replace(/l/g, "1").trim(); | |
| }; | |
| export const calculateBMI = (weightKg: number, heightCm: number): number => { | |
| const heightM = heightCm / 100; | |
| return Number((weightKg / (heightM * heightM)).toFixed(1)); | |
| }; | |