Files
thrilltrack-explorer/src-old/lib/locationFormatter.ts

65 lines
1.7 KiB
TypeScript

/**
* Location Formatting Utilities
*
* Centralized utilities for formatting location data consistently across the app.
*/
export interface LocationData {
street_address?: string | null;
city?: string | null;
state_province?: string | null;
country?: string | null;
postal_code?: string | null;
}
/**
* Format location for display
* @param location - Location data object
* @param includeStreet - Whether to include street address in the output
* @returns Formatted location string or null if no location data
*/
export function formatLocationDisplay(
location: LocationData | null | undefined,
includeStreet: boolean = false
): string | null {
if (!location) return null;
const parts: string[] = [];
if (includeStreet && location.street_address) {
parts.push(location.street_address);
}
if (location.city) {
parts.push(location.city);
}
if (location.state_province) {
parts.push(location.state_province);
}
if (location.country) {
parts.push(location.country);
}
return parts.length > 0 ? parts.join(', ') : null;
}
/**
* Format full address including street
* @param location - Location data object
* @returns Formatted full address or null if no location data
*/
export function formatFullAddress(location: LocationData | null | undefined): string | null {
return formatLocationDisplay(location, true);
}
/**
* Format location without street address (city, state, country only)
* @param location - Location data object
* @returns Formatted location without street or null if no location data
*/
export function formatLocationShort(location: LocationData | null | undefined): string | null {
return formatLocationDisplay(location, false);
}