Files
OpenSquawk/shared/utils/frequency.ts
2026-07-10 09:07:33 +02:00

11 lines
454 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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)
}