/** * Client-safe utility functions that can be shared between server and client code * These functions do not depend on Node.js modules and are safe for browser bundling */ // Boolean string formatting utility export const formatBooleanAsString = (value: boolean): string => { return value ? 'true' : 'false'; }; // Profile avatar utilities export const generateInitials = (firstName: string = '', lastName: string = ''): string => { const first = firstName?.charAt(0) || ''; const last = lastName?.charAt(0) || ''; return `${first}${last}`.toUpperCase(); }; export const generateAvatarColor = (id: string | number): string => { // High-contrast colors for better visibility const colors = [ 'red', 'blue', 'green', 'orange', 'purple', 'teal', 'indigo', 'pink', 'brown', 'deep-purple' ]; const idNumber = typeof id === 'string' ? parseInt(id) || 0 : id; return colors[Math.abs(idNumber) % colors.length]; }; // Member name formatting utility export const formatMemberName = (firstName: string = '', lastName: string = ''): string => { const fullName = `${firstName.trim()} ${lastName.trim()}`.trim(); return fullName || 'Unknown Member'; }; // Phone number formatting utility (client-safe version) export const formatPhoneDisplay = (phone: string): string => { if (!phone) return ''; // Remove all non-digits const cleaned = phone.replace(/\D/g, ''); // Format based on length if (cleaned.length === 10) { return `(${cleaned.substring(0, 3)}) ${cleaned.substring(3, 6)}-${cleaned.substring(6)}`; } else if (cleaned.length === 11 && cleaned.startsWith('1')) { return `+1 (${cleaned.substring(1, 4)}) ${cleaned.substring(4, 7)}-${cleaned.substring(7)}`; } return phone; // Return original if we can't format it };