Download frontend/src/shared/lib/format.ts from li2895/li: direct link, hf CLI and curl.
- Browser
- Download file 989 Bytes
-
https://huggingface.co/spaces/li2895/li/resolve/main/frontend/src/shared/lib/format.ts
- Command line
-
hf download hf://spaces/li2895/li/frontend/src/shared/lib/format.ts
-
curl -L -o format.ts https://huggingface.co/spaces/li2895/li/resolve/main/frontend/src/shared/lib/format.ts
989 Bytes
| export function formatDateTime(value: string | null | undefined, locale: string): string { | |
| if (!value) { | |
| return "-"; | |
| } | |
| const date = new Date(value); | |
| if (Number.isNaN(date.getTime())) { | |
| return "-"; | |
| } | |
| return new Intl.DateTimeFormat(locale, { | |
| dateStyle: "medium", | |
| timeStyle: "short", | |
| }).format(date); | |
| } | |
| export function formatNumber(value: number, locale: string, maximumFractionDigits = 2): string { | |
| return new Intl.NumberFormat(locale, { maximumFractionDigits }).format(value); | |
| } | |
| export function formatDuration(milliseconds: number): string { | |
| if (milliseconds < 1000) { | |
| return `${milliseconds} ms`; | |
| } | |
| return `${(milliseconds / 1000).toFixed(milliseconds < 10000 ? 2 : 1)} s`; | |
| } | |
| export function toDateTimeLocal(value: string | null | undefined): string { | |
| if (!value) { | |
| return ""; | |
| } | |
| const date = new Date(value); | |
| const offset = date.getTimezoneOffset() * 60_000; | |
| return new Date(date.getTime() - offset).toISOString().slice(0, 19); | |
| } | |