Serverpuls: Richtung, Vorzeichen und Stufen-Ton als Format-Helfer mit Test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-06 14:43:53 +00:00
1 parent 6adeac1642
commit bca99d4790
2 files changed
+31 -1

No files matched your search

+17
View File
@@ -57,6 +57,23 @@ export function formatNumber(v, digits = 2) {
return nf(digits).format(v)
}
// Richtung eines Kachel-Deltas: unter 1e-9 gilt als unverändert (flat).
export function deltaDir(d) {
return Math.abs(d) < 1e-9 ? 'flat' : d > 0 ? 'up' : 'down'
}
// Vorzeichen zur Richtung: '+', Minuszeichen U+2212, bei flat nichts.
export function deltaSign(dir) {
return dir === 'up' ? '+' : dir === 'down' ? '−' : ''
}
// Badge-Ton je Warnstufe; liest nur das erste Argument (.map(levelTone) reicht Index und Array mit).
const LEVEL_TONES = { ok: 'ok', medium: 'warn', critical: 'danger' }
export function levelTone(level) {
return Object.prototype.hasOwnProperty.call(LEVEL_TONES, level) ? LEVEL_TONES[level] : 'muted'
}
// --- Zeitachsen (Europe/Berlin, de-DE) ---
const TZ = 'Europe/Berlin'
const dtf = (opts) => new Intl.DateTimeFormat('de-DE', { timeZone: TZ, ...opts })