Files
ocean-cleanup/src/utils/index.ts
Paul Bailey 0e05769581 Rebrand application from 'Beach Litter Mapping Platform' to 'Litter Scouts'
- Updated app name in all source files, documentation, and configuration
- Changed package names in package.json files
- Updated header, titles, and user-facing text
- Modified email templates and notification text
- Updated steering rules and spec documents
2025-11-18 00:31:44 +00:00

63 lines
1.6 KiB
TypeScript

// Utility functions for Litter Scouts
// Re-export coordinate utilities
export * from './coordinates';
export * from './performance';
/**
* Formats a date to ISO 8601 format
*/
export function formatDateISO(date: Date): string {
return date.toISOString();
}
/**
* Calculates distance between two coordinates in meters using Haversine formula
*/
export function calculateDistance(
lat1: number,
lng1: number,
lat2: number,
lng2: number
): number {
const R = 6371e3; // Earth's radius in meters
const φ1 = (lat1 * Math.PI) / 180;
const φ2 = (lat2 * Math.PI) / 180;
const Δφ = ((lat2 - lat1) * Math.PI) / 180;
const Δλ = ((lng2 - lng1) * Math.PI) / 180;
const a =
Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c;
}
/**
* Validates file type for photo uploads
*/
export function isValidImageFile(file: File): boolean {
const validTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
return validTypes.includes(file.type);
}
/**
* Validates file size (max 5MB)
*/
export function isValidFileSize(file: File, maxSizeMB: number = 5): boolean {
const maxSizeBytes = maxSizeMB * 1024 * 1024;
return file.size <= maxSizeBytes;
}
/**
* Formats bytes to human-readable size
*/
export function formatFileSize(bytes: number): string {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
}