| 1234567891011121314151617181920212223242526272829303132333435363738 |
- /**
- * Get weather icon + description from Open-Meteo weather_code
- * @param {number} code - weather_code from the API
- * @param {number|boolean} isDay - 1 = daytime, 0 = nighttime (use response.current.is_day or hourly.is_day)
- * @returns {{icon: string, description: string}}
- */
- export default getWeatherInfo = (code, isDay = 1) => {
- const isDaytime = isDay === 1 || isDay === true;
- const map = {
- 0: { icon: isDaytime ? "☀️" : "🌙", desc: "Clear sky" },
- 1: { icon: isDaytime ? "🌤️" : "🌙", desc: "Mainly clear" },
- 2: { icon: isDaytime ? "⛅" : "🌥️", desc: "Partly cloudy" },
- 3: { icon: "☁️", desc: "Overcast" },
- 45: { icon: "🌫️", desc: "Fog" },
- 48: { icon: "🌫️", desc: "Depositing rime fog" },
- 51: { icon: "🌧️", desc: "Light drizzle" },
- 53: { icon: "🌧️", desc: "Moderate drizzle" },
- 55: { icon: "🌧️", desc: "Dense drizzle" },
- 61: { icon: "🌧️", desc: "Light rain" },
- 63: { icon: "🌧️", desc: "Moderate rain" },
- 65: { icon: "🌧️", desc: "Heavy rain" },
- 71: { icon: "❄️", desc: "Light snow" },
- 73: { icon: "❄️", desc: "Moderate snow" },
- 75: { icon: "❄️", desc: "Heavy snow" },
- 77: { icon: "❄️", desc: "Snow grains" },
- 80: { icon: "🌦️", desc: "Light rain showers" },
- 81: { icon: "🌧️", desc: "Moderate rain showers" },
- 82: { icon: "🌧️", desc: "Violent rain showers" },
- 85: { icon: "❄️", desc: "Light snow showers" },
- 86: { icon: "❄️", desc: "Heavy snow showers" },
- 95: { icon: "⛈️", desc: "Thunderstorm" },
- 96: { icon: "⛈️", desc: "Thunderstorm with slight hail" },
- 99: { icon: "⛈️", desc: "Thunderstorm with heavy hail" }
- };
- return map[code] || { icon: "❓", desc: "Unknown" };
- };
|