Spaces:
Sleeping
Sleeping
Download dashboard/src/utils/format.ts from SandeepChakka/store-intelligence: direct link, hf CLI and curl.
- Browser
- Download file 922 Bytes
-
https://huggingface.co/spaces/SandeepChakka/store-intelligence/resolve/main/dashboard/src/utils/format.ts
- Command line
-
hf download hf://spaces/SandeepChakka/store-intelligence/dashboard/src/utils/format.ts
-
curl -L -o format.ts https://huggingface.co/spaces/SandeepChakka/store-intelligence/resolve/main/dashboard/src/utils/format.ts
922 Bytes
| export function formatPercent(value: number | undefined | null, digits = 1): string { | |
| if (value === undefined || value === null || Number.isNaN(value)) return '—'; | |
| const pct = value <= 1 ? value * 100 : value; | |
| return `${pct.toFixed(digits)}%`; | |
| } | |
| export function formatNumber(value: number | undefined | null): string { | |
| if (value === undefined || value === null || Number.isNaN(value)) return '—'; | |
| return new Intl.NumberFormat().format(value); | |
| } | |
| export function formatRelativeTime(iso: string | null | undefined): string { | |
| if (!iso) return '—'; | |
| const then = new Date(iso).getTime(); | |
| if (Number.isNaN(then)) return iso; | |
| const diffSec = Math.round((Date.now() - then) / 1000); | |
| if (diffSec < 60) return `${diffSec}s ago`; | |
| if (diffSec < 3600) return `${Math.floor(diffSec / 60)}m ago`; | |
| if (diffSec < 86400) return `${Math.floor(diffSec / 3600)}h ago`; | |
| return new Date(iso).toLocaleString(); | |
| } | |