wayfarer-weather/lib/weather/describe.ts

19 lines
668 B
TypeScript
Raw Normal View History

2026-10-31 21:20:16 -05:00
import type { AlertSeverity, Condition } from "./types";
/** Fallback wording for providers that only give us a numeric code. */
export const CONDITION_LABELS: Record<Condition, string> = {
clear: "clear skies",
clouds: "cloudy",
rain: "rain",
storm: "thunderstorm",
snow: "snow",
fog: "fog",
};
/** Maps any provider's severity word ("Severe", "severe", "Moderate"…) onto ours. */
export function toSeverity(word: string | null | undefined): AlertSeverity {
const normalized = (word ?? "").toLowerCase();
const known: AlertSeverity[] = ["extreme", "severe", "moderate", "minor"];
return known.find((s) => normalized.includes(s)) ?? "unknown";
}