Spaces:
Running
Running
| export function quotaPercent(value) { | |
| const percent = Number(value); | |
| if (!Number.isFinite(percent)) { | |
| return null; | |
| } | |
| return Math.max(0, Math.min(100, percent)); | |
| } | |
| export function quotaRemainingPercent(quotaWindow) { | |
| if (!quotaWindow || typeof quotaWindow !== 'object') { | |
| return null; | |
| } | |
| const display = quotaPercent(quotaWindow.displayPercent ?? quotaWindow.display_percent); | |
| if (display !== null) { | |
| return display; | |
| } | |
| const explicit = quotaPercent(quotaWindow.remainingPercent ?? quotaWindow.remaining_percent); | |
| if (explicit !== null) { | |
| return explicit; | |
| } | |
| const used = quotaPercent(quotaWindow.usedPercent ?? quotaWindow.used_percent); | |
| return used === null ? null : Math.max(0, Math.min(100, 100 - used)); | |
| } | |
| export function formatQuotaPercent(quotaWindow) { | |
| const percent = quotaRemainingPercent(quotaWindow); | |
| return percent === null ? '--' : `${Math.round(percent)}%`; | |
| } | |
| export function quotaToneClass(percent) { | |
| if (percent === null) { | |
| return 'is-low'; | |
| } | |
| if (percent >= 80) { | |
| return 'is-healthy'; | |
| } | |
| if (percent >= 60) { | |
| return 'is-medium'; | |
| } | |
| if (percent >= 40) { | |
| return 'is-warning'; | |
| } | |
| return 'is-low'; | |
| } | |