31 lines
815 B
TypeScript
31 lines
815 B
TypeScript
/**
|
|
* @ai-summary Generic formatting utilities (no business logic)
|
|
* @ai-context Pure functions only, no feature-specific logic
|
|
*/
|
|
|
|
export function formatDate(date: Date): string {
|
|
return date.toISOString().split('T')[0];
|
|
}
|
|
|
|
export function formatDateTime(date: Date): string {
|
|
return date.toISOString();
|
|
}
|
|
|
|
export function formatCurrency(amount: number, currency = 'USD'): string {
|
|
return new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency,
|
|
}).format(amount);
|
|
}
|
|
|
|
export function formatDistance(meters: number): string {
|
|
if (meters < 1000) {
|
|
return `${Math.round(meters)}m`;
|
|
}
|
|
return `${(meters / 1000).toFixed(1)}km`;
|
|
}
|
|
|
|
export function formatMPG(miles: number, gallons: number): string {
|
|
if (gallons === 0) return '0 MPG';
|
|
return `${(miles / gallons).toFixed(1)} MPG`;
|
|
} |