weatherCodes.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Get weather icon + description from Open-Meteo weather_code
  3. * @param {number} code - weather_code from the API
  4. * @param {number|boolean} isDay - 1 = daytime, 0 = nighttime (use response.current.is_day or hourly.is_day)
  5. * @returns {{icon: string, description: string}}
  6. */
  7. export default getWeatherInfo = (code, isDay = 1) => {
  8. const isDaytime = isDay === 1 || isDay === true;
  9. const map = {
  10. 0: { icon: isDaytime ? "☀️" : "🌙", desc: "Clear sky" },
  11. 1: { icon: isDaytime ? "🌤️" : "🌙", desc: "Mainly clear" },
  12. 2: { icon: isDaytime ? "⛅" : "🌥️", desc: "Partly cloudy" },
  13. 3: { icon: "☁️", desc: "Overcast" },
  14. 45: { icon: "🌫️", desc: "Fog" },
  15. 48: { icon: "🌫️", desc: "Depositing rime fog" },
  16. 51: { icon: "🌧️", desc: "Light drizzle" },
  17. 53: { icon: "🌧️", desc: "Moderate drizzle" },
  18. 55: { icon: "🌧️", desc: "Dense drizzle" },
  19. 61: { icon: "🌧️", desc: "Light rain" },
  20. 63: { icon: "🌧️", desc: "Moderate rain" },
  21. 65: { icon: "🌧️", desc: "Heavy rain" },
  22. 71: { icon: "❄️", desc: "Light snow" },
  23. 73: { icon: "❄️", desc: "Moderate snow" },
  24. 75: { icon: "❄️", desc: "Heavy snow" },
  25. 77: { icon: "❄️", desc: "Snow grains" },
  26. 80: { icon: "🌦️", desc: "Light rain showers" },
  27. 81: { icon: "🌧️", desc: "Moderate rain showers" },
  28. 82: { icon: "🌧️", desc: "Violent rain showers" },
  29. 85: { icon: "❄️", desc: "Light snow showers" },
  30. 86: { icon: "❄️", desc: "Heavy snow showers" },
  31. 95: { icon: "⛈️", desc: "Thunderstorm" },
  32. 96: { icon: "⛈️", desc: "Thunderstorm with slight hail" },
  33. 99: { icon: "⛈️", desc: "Thunderstorm with heavy hail" }
  34. };
  35. return map[code] || { icon: "❓", desc: "Unknown" };
  36. };