/
merulaalba
/
WeatherApp
Обзор
Документация
Войти
/
merulaalba
/
WeatherApp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
scripts/helpers.js
109 строк
3 KB
merulaalba
sprint-1 done
07 июн 2026, 17:43
07 июн 2026, 17:43
6d07aae
Код
Авторство
О чём код?
const getPressureText = (pressure) => { if (pressure < 750) { return "Пониженное"; } else if (pressure >= 750 && pressure < 760) { return "Нормальное"; } else { return "Повышенное"; } } const getViewText = (view) => { return view < 1 ? "Ограниченная" : "Нормальная"; } const pressureToPercent = (pressure) => { const MIN_PRESSURE = 600; const MAX_PRESSURE = 814; if (pressure < MIN_PRESSURE || pressure > MAX_PRESSURE) { return "0"; } const percentage = Math.round(((pressure - MIN_PRESSURE) / (MAX_PRESSURE - MIN_PRESSURE)) * 100); return percentage; } const setThumbValue = (item, value) => { const bar = item.querySelector(".progress__bar"); const thumb = item.querySelector(".progress__thumb"); if (value <= 4) { bar.style.maskImage = "radial-gradient(circle at 4%, transparent 6px, black 6px)"; thumb.style.left = "4%"; } else if (value >= 96) { bar.style.maskImage = "radial-gradient(circle at 96%, transparent 6px, black 6px)"; thumb.style.left = "96%"; } else { bar.style.maskImage = `radial-gradient(circle at ${value}%, transparent 6px, black 6px)`; thumb.style.left = `${value}%`; } } const getWeatherPictogram = (weather, time, dictionary) => { const hour = time.split(":")[0]; const day = hour > 6 && hour < 20; if (weather === "Ясно") { if (hour.length === 2) { return day ? dictionary.clearSkyDay : dictionary.clearSkyNight; } else { return dictionary.clearSkyDay; } } if (weather === "Облачно с прояснениями") { if (hour.length === 2) { return day ? dictionary.fewCloudsDay : dictionary.fewCloudsNight; } else { return dictionary.fewCloudsDay; } } if (weather === "Переменная облачность") { if (hour.length === 2) { return day ? dictionary.scatteredCloudsDay : dictionary.scatteredCloudsNight; } else { return dictionary.scatteredCloudsDay; } } if (weather === "Дождь") { if(hour.length === 2) { return day ? dictionary.rainDay : dictionary.rainNight; } else { return dictionary.rainDay; } } if (weather === "Облачно") { return dictionary.brokenClouds; } if (weather === "Ливень") { return dictionary.showerRain; } if (weather === "Гроза") { return dictionary.thunderstorm; } if (weather === "Снег") { return dictionary.snow; } if (weather === "Туман") { return dictionary.mist; } } const debounce = (func, delay) => { let timeoutId; return function(...args) { const context = this; clearTimeout(timeoutId); timeoutId = setTimeout(() => func.apply(context, args), delay); }; } export { getPressureText, getViewText, pressureToPercent, setThumbValue, getWeatherPictogram, debounce };