chore: add prettier formatting
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m56s
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m56s
This commit is contained in:
@@ -85,10 +85,14 @@ export function normalizeHydroStation(raw: RawHydroStation): HydroStation | null
|
||||
}
|
||||
|
||||
export function normalizeWarning(raw: RawWarning, kind: WarningKind, index: number): WeatherWarning {
|
||||
const provinces = [...new Set([
|
||||
...(raw.obszary ?? []).map((area) => normalizeProvinceName(area.wojewodztwo)),
|
||||
...(raw.teryt ?? []).map(getProvinceFromTeryt),
|
||||
].filter((province) => province !== null))];
|
||||
const provinces = [
|
||||
...new Set(
|
||||
[
|
||||
...(raw.obszary ?? []).map((area) => normalizeProvinceName(area.wojewodztwo)),
|
||||
...(raw.teryt ?? []).map(getProvinceFromTeryt),
|
||||
].filter((province) => province !== null),
|
||||
),
|
||||
];
|
||||
const describedAreas = (raw.obszary ?? [])
|
||||
.map((area) => area.opis?.trim() || area.wojewodztwo?.trim())
|
||||
.filter((area): area is string => Boolean(area));
|
||||
@@ -106,7 +110,9 @@ export function normalizeWarning(raw: RawWarning, kind: WarningKind, index: numb
|
||||
publishedAt: normalizeDate(raw.opublikowano),
|
||||
probability: toNumber(raw.prawdopodobienstwo),
|
||||
areas,
|
||||
terytCodes: Array.isArray(raw.teryt) ? raw.teryt.filter((code): code is string => typeof code === "string" && code.trim().length > 0) : [],
|
||||
terytCodes: Array.isArray(raw.teryt)
|
||||
? raw.teryt.filter((code): code is string => typeof code === "string" && code.trim().length > 0)
|
||||
: [],
|
||||
provinces,
|
||||
office: raw.biuro?.trim() || null,
|
||||
};
|
||||
@@ -125,15 +131,25 @@ export function convertTemperature(value: number, unit: TemperatureUnit) {
|
||||
return value;
|
||||
}
|
||||
|
||||
export function formatTemperatureValue(value: number, language: Language = "pl", unit: TemperatureUnit = DEFAULT_TEMPERATURE_UNIT) {
|
||||
export function formatTemperatureValue(
|
||||
value: number,
|
||||
language: Language = "pl",
|
||||
unit: TemperatureUnit = DEFAULT_TEMPERATURE_UNIT,
|
||||
) {
|
||||
const formattedValue = new Intl.NumberFormat(locales[language], {
|
||||
maximumFractionDigits: 0,
|
||||
}).format(value);
|
||||
return `${formattedValue}${getTemperatureUnitLabel(unit)}`;
|
||||
}
|
||||
|
||||
export function formatTemperature(value: number | null, language: Language = "pl", unit: TemperatureUnit = DEFAULT_TEMPERATURE_UNIT) {
|
||||
return value === null ? translate(language, "common.noData") : formatTemperatureValue(convertTemperature(value, unit), language, unit);
|
||||
export function formatTemperature(
|
||||
value: number | null,
|
||||
language: Language = "pl",
|
||||
unit: TemperatureUnit = DEFAULT_TEMPERATURE_UNIT,
|
||||
) {
|
||||
return value === null
|
||||
? translate(language, "common.noData")
|
||||
: formatTemperatureValue(convertTemperature(value, unit), language, unit);
|
||||
}
|
||||
|
||||
export function formatPressure(value: number | null, language: Language = "pl") {
|
||||
@@ -158,7 +174,11 @@ export function convertWindSpeed(speed: number, unit: WindSpeedUnit) {
|
||||
return speed;
|
||||
}
|
||||
|
||||
export function formatWindSpeed(speed: number | null, language: Language = "pl", unit: WindSpeedUnit = DEFAULT_WIND_SPEED_UNIT) {
|
||||
export function formatWindSpeed(
|
||||
speed: number | null,
|
||||
language: Language = "pl",
|
||||
unit: WindSpeedUnit = DEFAULT_WIND_SPEED_UNIT,
|
||||
) {
|
||||
if (speed === null) return translate(language, "common.noData");
|
||||
const convertedSpeed = convertWindSpeed(speed, unit);
|
||||
const digits = unit === "ms" ? 1 : 0;
|
||||
@@ -169,7 +189,12 @@ export function formatWindSpeed(speed: number | null, language: Language = "pl",
|
||||
return `${formattedSpeed} ${getWindSpeedUnitLabel(unit)}`;
|
||||
}
|
||||
|
||||
export function formatWind(speed: number | null, direction?: number | null, language: Language = "pl", unit: WindSpeedUnit = DEFAULT_WIND_SPEED_UNIT) {
|
||||
export function formatWind(
|
||||
speed: number | null,
|
||||
direction?: number | null,
|
||||
language: Language = "pl",
|
||||
unit: WindSpeedUnit = DEFAULT_WIND_SPEED_UNIT,
|
||||
) {
|
||||
if (speed === null) return translate(language, "common.noData");
|
||||
const directionLabel = direction === null || direction === undefined ? "" : ` ${getWindDirection(direction)}`;
|
||||
return `${formatWindSpeed(speed, language, unit)}${directionLabel}`;
|
||||
@@ -187,7 +212,11 @@ export function formatFlow(value: number | null, language: Language = "pl") {
|
||||
return value === null ? translate(language, "common.noData") : `${value.toFixed(2)} m³/s`;
|
||||
}
|
||||
|
||||
export function formatDateTime(value: string | null, language: Language = "pl", fallback = translate(language, "common.noData")) {
|
||||
export function formatDateTime(
|
||||
value: string | null,
|
||||
language: Language = "pl",
|
||||
fallback = translate(language, "common.noData"),
|
||||
) {
|
||||
if (!value) return fallback;
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return fallback;
|
||||
@@ -215,9 +244,17 @@ export function calculateFeelsLike(temperature: number | null, humidity: number
|
||||
const c7 = 0.002211732;
|
||||
const c8 = 0.00072546;
|
||||
const c9 = -0.000003582;
|
||||
return c1 + c2 * temperature + c3 * humidity + c4 * temperature * humidity + c5 * temperature ** 2 +
|
||||
c6 * humidity ** 2 + c7 * temperature ** 2 * humidity + c8 * temperature * humidity ** 2 +
|
||||
c9 * temperature ** 2 * humidity ** 2;
|
||||
return (
|
||||
c1 +
|
||||
c2 * temperature +
|
||||
c3 * humidity +
|
||||
c4 * temperature * humidity +
|
||||
c5 * temperature ** 2 +
|
||||
c6 * humidity ** 2 +
|
||||
c7 * temperature ** 2 * humidity +
|
||||
c8 * temperature * humidity ** 2 +
|
||||
c9 * temperature ** 2 * humidity ** 2
|
||||
);
|
||||
}
|
||||
return temperature;
|
||||
}
|
||||
@@ -243,8 +280,10 @@ function getForecastConditionDescription(code: number | null, language: Language
|
||||
if (code === 3) return translate(language, "forecast.condition.cloudy");
|
||||
if (code === 45 || code === 48) return translate(language, "forecast.condition.fog");
|
||||
if (code !== null && code >= 51 && code <= 57) return translate(language, "forecast.condition.drizzle");
|
||||
if (code !== null && ((code >= 61 && code <= 67) || (code >= 80 && code <= 82))) return translate(language, "forecast.condition.rain");
|
||||
if (code !== null && ((code >= 71 && code <= 77) || code === 85 || code === 86)) return translate(language, "forecast.condition.snow");
|
||||
if (code !== null && ((code >= 61 && code <= 67) || (code >= 80 && code <= 82)))
|
||||
return translate(language, "forecast.condition.rain");
|
||||
if (code !== null && ((code >= 71 && code <= 77) || code === 85 || code === 86))
|
||||
return translate(language, "forecast.condition.snow");
|
||||
if (code !== null && code >= 95) return translate(language, "forecast.condition.thunderstorm");
|
||||
return null;
|
||||
}
|
||||
@@ -270,7 +309,11 @@ export function getWeatherDescription(
|
||||
if ((station.windSpeed ?? 0) >= 8) return translate(language, "weather.strongWind");
|
||||
const currentDescription = getForecastConditionDescription(currentWeatherCode ?? null, language);
|
||||
const cloudCoverDescription = getCloudCoverDescription(currentCloudCover, language);
|
||||
if (cloudCoverDescription && (currentWeatherCode === null || currentWeatherCode === undefined || currentWeatherCode === 0)) return cloudCoverDescription;
|
||||
if (
|
||||
cloudCoverDescription &&
|
||||
(currentWeatherCode === null || currentWeatherCode === undefined || currentWeatherCode === 0)
|
||||
)
|
||||
return cloudCoverDescription;
|
||||
if (currentDescription) return currentDescription;
|
||||
if (cloudCoverDescription) return cloudCoverDescription;
|
||||
const forecastDescription = getForecastConditionDescription(forecastWeatherCode ?? null, language);
|
||||
|
||||
Reference in New Issue
Block a user