( value: string, format?: JSONDateTimeFormat )
| 104 | } |
| 105 | |
| 106 | export function formatDateTime( |
| 107 | value: string, |
| 108 | format?: JSONDateTimeFormat |
| 109 | ): string { |
| 110 | if (!format) { |
| 111 | return value; |
| 112 | } |
| 113 | |
| 114 | const temporal = inferTemporal(value, format); |
| 115 | |
| 116 | if (!temporal) { |
| 117 | return value; |
| 118 | } |
| 119 | |
| 120 | switch (format.parts) { |
| 121 | case "datetime": |
| 122 | return temporal.toLocaleString("en-US", { |
| 123 | year: "numeric", |
| 124 | month: "short", |
| 125 | day: "numeric", |
| 126 | hour: "numeric", |
| 127 | minute: "numeric", |
| 128 | second: "numeric", |
| 129 | timeZoneName: "short", |
| 130 | }); |
| 131 | case "date": |
| 132 | return temporal.toLocaleString("en-US", { |
| 133 | year: "numeric", |
| 134 | month: "short", |
| 135 | day: "numeric", |
| 136 | }); |
| 137 | case "time": |
| 138 | return temporal.toLocaleString("en-US", { |
| 139 | hour: "numeric", |
| 140 | minute: "numeric", |
| 141 | second: "numeric", |
| 142 | }); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | export function formatBytes(bytes: number, decimals = 2): string { |
| 147 | if (bytes === 0) return "0 Bytes"; |
no test coverage detected