Normalize Wunderground labels to METAR

This commit is contained in:
2569718930@qq.com
2026-04-22 23:43:27 +08:00
parent e3a9f7fb00
commit fe804bc915
8 changed files with 81 additions and 34 deletions
+24
View File
@@ -0,0 +1,24 @@
export function normalizeObservationSourceLabel(
value?: string | null,
fallback = "METAR",
) {
const raw = String(value || "").trim();
if (!raw) return fallback;
const lowered = raw.toLowerCase();
if (
lowered === "wu" ||
lowered === "wunderground"
) {
return "METAR";
}
if (lowered.includes("wunderground")) {
return raw.replace(/wunderground/gi, "METAR");
}
return raw;
}
export function normalizeObservationSourceCode(value?: string | null) {
const code = String(value || "").trim().toLowerCase();
if (code === "wu" || code === "wunderground") return "metar";
return code;
}