(raw: unknown, defaultLabel: string)
| 75 | } |
| 76 | |
| 77 | function toUsageRow(raw: unknown, defaultLabel: string): UsageRow | null { |
| 78 | if (!isRecord(raw)) return null; |
| 79 | const limit = toInt(raw['limit']); |
| 80 | let used = toInt(raw['used']); |
| 81 | if (used === null) { |
| 82 | const remaining = toInt(raw['remaining']); |
| 83 | if (remaining !== null && limit !== null) { |
| 84 | used = limit - remaining; |
| 85 | } |
| 86 | } |
| 87 | if (used === null && limit === null) return null; |
| 88 | const name = |
| 89 | typeof raw['name'] === 'string' |
| 90 | ? raw['name'] |
| 91 | : typeof raw['title'] === 'string' |
| 92 | ? raw['title'] |
| 93 | : defaultLabel; |
| 94 | const resetHint = resetHintFrom(raw); |
| 95 | return { |
| 96 | label: name, |
| 97 | used: used ?? 0, |
| 98 | limit: limit ?? 0, |
| 99 | resetHint, |
| 100 | }; |
| 101 | } |
| 102 | |
| 103 | function limitLabel( |
| 104 | item: Record<string, unknown>, |
no test coverage detected