import type { FileInputItem } from './hooks'; export const IMAGE_FILE_EXTENSION_REGEX = /\.(avif|bmp|gif|heic|heif|ico|jpe?g|png|svg|webp)$/i; export const getFileName = (file: FileInputItem) => { if (typeof file === 'string') { return file; } return file.name; }; export const getFileExtension = (file: FileInputItem) => { const parts = getFileName(file).split('.'); return parts.length > 1 ? `.${parts.pop()}` : ''; }; const isImageFileUrl = (value: string) => { const normalizedValue = value.split(/[?#]/)[0] || ''; return value.startsWith('data:image/') || IMAGE_FILE_EXTENSION_REGEX.test(normalizedValue); }; export const getImagePreviewSource = (file: FileInputItem) => { if (typeof file === 'string') { return isImageFileUrl(file) ? file : undefined; } return undefined; };