Spaces:
Sleeping
Sleeping
Download frontend/src/utils/formatters.js from haisyam/PlatDetect: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/haisyam/PlatDetect/resolve/main/frontend/src/utils/formatters.js
- Command line
-
hf download hf://spaces/haisyam/PlatDetect/frontend/src/utils/formatters.js
-
curl -L -o formatters.js https://huggingface.co/spaces/haisyam/PlatDetect/resolve/main/frontend/src/utils/formatters.js
1.5 kB
| /** | |
| * Format confidence YOLO menjadi persentase. | |
| * Contoh: 0.87 -> "87%" | |
| */ | |
| export function formatConfidence(value) { | |
| if (value === null || value === undefined) return "-"; | |
| const num = parseFloat(value); | |
| if (isNaN(num)) return "-"; | |
| return `${Math.round(num * 100)}%`; | |
| } | |
| /** | |
| * Format ukuran file menjadi human-readable. | |
| * Contoh: 1048576 -> "1.0 MB" | |
| */ | |
| export function formatFileSize(bytes) { | |
| if (!bytes) return ""; | |
| const units = ["B", "KB", "MB", "GB"]; | |
| let unitIndex = 0; | |
| let size = bytes; | |
| while (size >= 1024 && unitIndex < units.length - 1) { | |
| size /= 1024; | |
| unitIndex++; | |
| } | |
| return `${size.toFixed(1)} ${units[unitIndex]}`; | |
| } | |
| /** | |
| * Validasi apakah file merupakan gambar yang didukung. | |
| */ | |
| export function isValidImageFile(file) { | |
| const validTypes = [ | |
| "image/jpeg", | |
| "image/jpg", | |
| "image/png", | |
| "image/webp", | |
| ]; | |
| return validTypes.includes(file.type); | |
| } | |
| /** | |
| * Cek apakah ukuran file tidak melebihi batas (default 10MB). | |
| */ | |
| export function isFileSizeValid(file, maxSizeMB = 10) { | |
| return file.size <= maxSizeMB * 1024 * 1024; | |
| } | |
| /** | |
| * Format waktu deteksi. | |
| * Contoh: "2026-06-08 10:30:12" -> "08 Jun 2026, 10:30" | |
| */ | |
| export function formatDateTime(dateStr) { | |
| if (!dateStr) return "-"; | |
| try { | |
| const date = new Date(dateStr); | |
| return date.toLocaleDateString("id-ID", { | |
| day: "2-digit", | |
| month: "short", | |
| year: "numeric", | |
| hour: "2-digit", | |
| minute: "2-digit", | |
| }); | |
| } catch { | |
| return dateStr; | |
| } | |
| } | |