const getClientLocale = (): string => { return navigator.languages.length > 0 ? navigator.languages[0] : "en-US"; }; const getAge = (dateOfBirth: Date): number => { const today = new Date(); const thisYear = today.getFullYear(); const thisMonth = today.getMonth(); const thisDay = today.getDate(); const dobYear = dateOfBirth.getFullYear(); const dobMonth = dateOfBirth.getMonth(); const dobDay = dateOfBirth.getDate(); let age = thisYear - dobYear; if (thisMonth < dobMonth) age--; if (thisMonth === dobMonth && thisDay < dobDay) age--; return age; }; const toImperial = (cm: number): string => { const realFeet = (cm * 0.3937) / 12; const feet = Math.floor(realFeet); const inches = Math.round((realFeet - feet) * 12); return `${feet}'${inches}"`; }; const toInch = (cm: number): string => { return `${Math.round(cm / 2.45)} in`; }; const toLbs = (kg: number): number => { const nearExact = kg / 0.45359237; const lbs = Math.floor(nearExact); return lbs; }; const toFahrenheit = (celsius: number): number => { return celsius * 1.8 + 32; }; const dateFormat = new Intl.DateTimeFormat(getClientLocale(), { year: "numeric", month: "long", day: "2-digit", }); export { getClientLocale, getAge, toImperial, toInch, toLbs, toFahrenheit, dateFormat, };