Files
Caregiver/src/utils/formatters.ts
T
2026-08-14 17:41:45 +05:30

31 lines
941 B
TypeScript

/**
* Formats a rating number to a string with one decimal place.
* Example: 4.8123 -> "4.8"
*/
export const formatRating = (rating: number): string => {
return rating.toFixed(1);
};
/**
* Returns initials from a full name.
* Example: "Sarah Jenkins" -> "S"
*/
export const getInitials = (name: string): string => {
return name.charAt(0).toUpperCase();
};
import { ENV } from '../config/env';
/**
* Returns a full URL for an image path.
*/
export const getImageUrl = (path?: string | null): string | undefined => {
if (!path) return undefined;
if (path.startsWith('http://') || path.startsWith('https://') || path.startsWith('file://') || path.startsWith('content://') || path.startsWith('data:')) {
return path;
}
const baseUrl = ENV.API_BASE_URL.endsWith('/') ? ENV.API_BASE_URL.slice(0, -1) : ENV.API_BASE_URL;
const imagePath = path.startsWith('/') ? path : `/${path}`;
return `${baseUrl}${imagePath}`;
};