mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-09 02:56:02 +08:00
refactor(live-atc): extract normalizeManualFreq to shared/utils, add tests
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
10
shared/utils/frequency.ts
Normal file
10
shared/utils/frequency.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
// Accepts inputs like "121.5", "121,500" or "118" and normalises to a valid
|
||||
// VHF airband frequency string (118.000–136.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)
|
||||
}
|
||||
Reference in New Issue
Block a user