refactor(live-atc): extract normalizeManualFreq to shared/utils, add tests

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
itsrubberduck
2026-07-10 09:07:33 +02:00
parent fb25af913a
commit 5e266c0733
3 changed files with 37 additions and 11 deletions

10
shared/utils/frequency.ts Normal file
View File

@@ -0,0 +1,10 @@
// Accepts inputs like "121.5", "121,500" or "118" and normalises to a valid
// VHF airband frequency string (118.000136.975). Returns null when invalid so
// callers/UI can disable the action.
export function normalizeManualFreq(input: string): string | null {
const raw = input.trim().replace(',', '.')
if (!raw) return null
const num = Number(raw)
if (!Number.isFinite(num) || num < 118 || num >= 137) return null
return num.toFixed(3)
}