diff --git a/app/lib/format.ts b/app/lib/format.ts new file mode 100644 index 0000000..996eb2a --- /dev/null +++ b/app/lib/format.ts @@ -0,0 +1,17 @@ +const dateFormatter = new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short', year: 'numeric' }); + +export function formatDate(value: string): string { + const date = new Date(value); + return Number.isNaN(date.getTime()) ? '' : dateFormatter.format(date); +} + +export function formatFileSize(bytes: number): string { + if (bytes < 1024 * 1024) return `${Math.max(1, Math.round(bytes / 1024))} KB`; + return `${(bytes / 1024 / 1024).toFixed(2)} MB`; +} + +export const fileTypeLabel = (file: File) => (file.type.split('/').pop() ?? '').toUpperCase(); + +export function toFileName(value: string): string { + return value.trim().replace(/\s+/g, '_'); +}